From ece78684d9e09c477c4a0f10236c0aec45bac726 Mon Sep 17 00:00:00 2001 From: Fabrizio Ettore Messina Date: Thu, 13 Aug 2015 10:03:20 +0200 Subject: [PATCH] Fixed #25267 -- Corrected message for admin.E122 system check. --- django/contrib/admin/checks.py | 11 +++++++++-- tests/admin_checks/tests.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index c74e8b96c2..62cce24af6 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -774,8 +774,15 @@ class ModelAdminChecks(BaseModelAdminChecks): model=model, obj=cls, id='admin.E121') else: if field_name not in cls.list_display: - return refer_to_missing_field(field=field_name, option=label, - model=model, obj=cls, id='admin.E122') + return [ + checks.Error( + "The value of '%s' refers to '%s', which is not " + "contained in 'list_display'." % (label, field_name), + hint=None, + obj=cls, + id='admin.E122', + ) + ] elif cls.list_display_links and field_name in cls.list_display_links: return [ checks.Error( diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index 0b4d905c1b..84f4439fe2 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -69,6 +69,22 @@ class SystemChecksTestCase(SimpleTestCase): custom_site.unregister(Song) admin.sites.system_check_errors = [] + def test_field_name_not_in_list_display(self): + class SongAdmin(admin.ModelAdmin): + list_editable = ["original_release"] + + errors = SongAdmin.check(model=Song) + expected = [ + checks.Error( + "The value of 'list_editable[0]' refers to 'original_release', " + "which is not contained in 'list_display'.", + hint=None, + obj=SongAdmin, + id='admin.E122', + ) + ] + self.assertEqual(errors, expected) + def test_readonly_and_editable(self): class SongAdmin(admin.ModelAdmin): readonly_fields = ["original_release"]