diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py index 4f23296eca..0397e8557a 100644 --- a/tests/admin_changelist/admin.py +++ b/tests/admin_changelist/admin.py @@ -33,6 +33,7 @@ site.register(Event, EventAdmin) class ParentAdmin(admin.ModelAdmin): list_filter = ['child__name'] search_fields = ['child__name'] + list_select_related = ['child'] class ChildAdmin(admin.ModelAdmin): diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 8da1c2f799..dc1b987a1e 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -104,6 +104,20 @@ class ChangeListTests(TestCase): cl = m.get_changelist_instance(request) self.assertEqual(cl.queryset.query.select_related, {'parent': {}}) + def test_select_related_preserved_when_multi_valued_in_search_fields(self): + parent = Parent.objects.create(name='Mary') + Child.objects.create(parent=parent, name='Danielle') + Child.objects.create(parent=parent, name='Daniel') + + m = ParentAdmin(Parent, custom_site) + request = self.factory.get('/parent/', data={SEARCH_VAR: 'daniel'}) + request.user = self.superuser + + cl = m.get_changelist_instance(request) + self.assertEqual(cl.queryset.count(), 1) + # select_related is preserved. + self.assertEqual(cl.queryset.query.select_related, {'child': {}}) + def test_select_related_as_tuple(self): ia = InvitationAdmin(Invitation, custom_site) request = self.factory.get('/invitation/')