Refs #19080 -- Added tests for preserving select_related() in the admin changelist.
This commit is contained in:
parent
d68be0494b
commit
158eca4f93
|
@ -33,6 +33,7 @@ site.register(Event, EventAdmin)
|
||||||
class ParentAdmin(admin.ModelAdmin):
|
class ParentAdmin(admin.ModelAdmin):
|
||||||
list_filter = ['child__name']
|
list_filter = ['child__name']
|
||||||
search_fields = ['child__name']
|
search_fields = ['child__name']
|
||||||
|
list_select_related = ['child']
|
||||||
|
|
||||||
|
|
||||||
class ChildAdmin(admin.ModelAdmin):
|
class ChildAdmin(admin.ModelAdmin):
|
||||||
|
|
|
@ -104,6 +104,20 @@ class ChangeListTests(TestCase):
|
||||||
cl = m.get_changelist_instance(request)
|
cl = m.get_changelist_instance(request)
|
||||||
self.assertEqual(cl.queryset.query.select_related, {'parent': {}})
|
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):
|
def test_select_related_as_tuple(self):
|
||||||
ia = InvitationAdmin(Invitation, custom_site)
|
ia = InvitationAdmin(Invitation, custom_site)
|
||||||
request = self.factory.get('/invitation/')
|
request = self.factory.get('/invitation/')
|
||||||
|
|
Loading…
Reference in New Issue