diff options
| author | krishbharadwaj <krishna.bmsce@gmail.com> | 2016-04-23 23:05:18 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-08 17:20:03 -0400 |
| commit | f6681393d3f53a67b4e0645e8d02f95579d8ae2d (patch) | |
| tree | e948ad4c71febd776f62a1260f2038066c91fcc8 /tests | |
| parent | c8d2120b06e1b82cb0db896aa0f9767b2f14256c (diff) | |
Fixing #26524 -- Made a foreign key id reference in ModelAdmin.list_display display the id.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_utils/tests.py | 1 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 12 |
2 files changed, 13 insertions, 0 deletions
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 <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'). |
