mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #20235 -- Use self.object_list if object_list not present in get_context_data kwargs.
This is so MultipleObjectMixin can be used in the same way as SingleObjectMixin.
This commit is contained in:
parent
9012a9e200
commit
1c921cfac3
4 changed files with 34 additions and 2 deletions
|
@ -411,3 +411,23 @@ class GetContextDataTest(unittest.TestCase):
|
|||
# test that kwarg overrides values assigned higher up
|
||||
context = test_view.get_context_data(test_name='test_value')
|
||||
self.assertEqual(context['test_name'], 'test_value')
|
||||
|
||||
|
||||
class UseMultipleObjectMixinTest(unittest.TestCase):
|
||||
rf = RequestFactory()
|
||||
|
||||
def test_use_queryset_from_view(self):
|
||||
test_view = views.CustomMultipleObjectMixinView()
|
||||
test_view.get(self.rf.get('/'))
|
||||
# Don't pass queryset as argument
|
||||
context = test_view.get_context_data()
|
||||
self.assertEqual(context['object_list'], test_view.queryset)
|
||||
|
||||
def test_overwrite_queryset(self):
|
||||
test_view = views.CustomMultipleObjectMixinView()
|
||||
test_view.get(self.rf.get('/'))
|
||||
queryset = [{'name': 'Lennon'}, {'name': 'Ono'}]
|
||||
self.assertNotEqual(test_view.queryset, queryset)
|
||||
# Overwrite the view's queryset with queryset from kwarg
|
||||
context = test_view.get_context_data(object_list=queryset)
|
||||
self.assertEqual(context['object_list'], queryset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue