From 89c27d867252d7c81be3de7184578db1934a9318 Mon Sep 17 00:00:00 2001 From: nessita <124304+nessita@users.noreply.github.com> Date: Mon, 5 Jun 2023 00:56:53 -0300 Subject: [PATCH] Fixed #34601 -- Added field name to check message for ModelAdmin.readonly_fields. Co-authored-by: Rick van Hattem --- django/contrib/admin/checks.py | 5 +++-- docs/ref/checks.txt | 5 +++-- tests/admin_checks/tests.py | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index c395b0bde2..2c90dedc31 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -771,10 +771,11 @@ class BaseModelAdminChecks: except FieldDoesNotExist: return [ checks.Error( - "The value of '%s' is not a callable, an attribute of " - "'%s', or an attribute of '%s'." + "The value of '%s' refers to '%s', which is not a callable, " + "an attribute of '%s', or an attribute of '%s'." % ( label, + field_name, obj.__class__.__name__, obj.model._meta.label, ), diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index df0adbef63..1b2306b2af 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -675,8 +675,9 @@ with the admin site: * **admin.E033**: The value of ``ordering`` refers to ````, which is not a field of ````. * **admin.E034**: The value of ``readonly_fields`` must be a list or tuple. -* **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an - attribute of ````, or an attribute of ````. +* **admin.E035**: The value of ``readonly_fields[n]`` refers to + ````, which is not a callable, an attribute of + ````, or an attribute of ````. * **admin.E036**: The value of ``autocomplete_fields`` must be a list or tuple. * **admin.E037**: The value of ``autocomplete_fields[n]`` refers to ````, which is not a field of ````. diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index 4d171ed737..417c8504ed 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -798,8 +798,9 @@ class SystemChecksTestCase(SimpleTestCase): errors = SongAdmin(Song, AdminSite()).check() expected = [ checks.Error( - "The value of 'readonly_fields[1]' is not a callable, an attribute " - "of 'SongAdmin', or an attribute of 'admin_checks.Song'.", + "The value of 'readonly_fields[1]' refers to 'nonexistent', which is " + "not a callable, an attribute of 'SongAdmin', or an attribute of " + "'admin_checks.Song'.", obj=SongAdmin, id="admin.E035", ) @@ -814,8 +815,9 @@ class SystemChecksTestCase(SimpleTestCase): errors = CityInline(State, AdminSite()).check() expected = [ checks.Error( - "The value of 'readonly_fields[0]' is not a callable, an attribute " - "of 'CityInline', or an attribute of 'admin_checks.City'.", + "The value of 'readonly_fields[0]' refers to 'i_dont_exist', which is " + "not a callable, an attribute of 'CityInline', or an attribute of " + "'admin_checks.City'.", obj=CityInline, id="admin.E035", )