From f6681393d3f53a67b4e0645e8d02f95579d8ae2d Mon Sep 17 00:00:00 2001 From: krishbharadwaj Date: Sat, 23 Apr 2016 23:05:18 +0530 Subject: Fixing #26524 -- Made a foreign key id reference in ModelAdmin.list_display display the id. --- tests/admin_utils/tests.py | 1 + tests/admin_views/tests.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index ecb084adbe..2e72f5a05d 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -259,6 +259,7 @@ class UtilsTests(SimpleTestCase): label_for_field(lambda x: "nothing", Article), "--" ) + self.assertEqual(label_for_field('site_id', Article), 'Site id') class MockModelAdmin(object): def test_from_model(self, obj): diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 6455b210b2..e706ba7105 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -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 _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'). -- cgit v1.3