1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixing #26524 -- Made a foreign key id reference in ModelAdmin.list_display display the id.

This commit is contained in:
krishbharadwaj
2016-04-23 23:05:18 +05:30
committed by Tim Graham
parent c8d2120b06
commit f6681393d3
5 changed files with 36 additions and 2 deletions

View File

@@ -538,6 +538,18 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
self.assertContentBefore(response, 'The First Item', 'The Middle Item')
self.assertContentBefore(response, 'The Middle Item', 'The Last Item')
def test_has_related_field_in_list_display(self):
"""Joins shouldn't be performed for <FK>_id fields in list display."""
state = State.objects.create(name='Karnataka')
City.objects.create(state=state, name='Bangalore')
response = self.client.get(reverse('admin:admin_views_city_changelist'), {})
response.context['cl'].list_display = ['id', 'name', 'state']
self.assertEqual(response.context['cl'].has_related_field_in_list_display(), True)
response.context['cl'].list_display = ['id', 'name', 'state_id']
self.assertEqual(response.context['cl'].has_related_field_in_list_display(), False)
def test_limited_filter(self):
"""Ensure admin changelist filters do not contain objects excluded via limit_choices_to.
This also tests relation-spanning filters (e.g. 'color__value').