Browse Source

Fixed #34601 -- Added field name to check message for ModelAdmin.readonly_fields.

Co-authored-by: Rick van Hattem <wolph@wol.ph>
nessita 1 year ago
parent
commit
89c27d8672
3 changed files with 12 additions and 8 deletions
  1. 3 2
      django/contrib/admin/checks.py
  2. 3 2
      docs/ref/checks.txt
  3. 6 4
      tests/admin_checks/tests.py

+ 3 - 2
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,
                         ),

+ 3 - 2
docs/ref/checks.txt

@@ -675,8 +675,9 @@ with the admin site:
 * **admin.E033**: The value of ``ordering`` refers to ``<field name>``, which
   is not a field of ``<model>``.
 * **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 ``<ModelAdmin class>``, or an attribute of ``<model>``.
+* **admin.E035**: The value of ``readonly_fields[n]`` refers to
+  ``<field_name>``, which is not a callable, an attribute of
+  ``<ModelAdmin class>``, or an attribute of ``<model>``.
 * **admin.E036**: The value of ``autocomplete_fields`` must be a list or tuple.
 * **admin.E037**: The value of ``autocomplete_fields[n]`` refers to
   ``<field name>``, which is not a field of ``<model>``.

+ 6 - 4
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",
             )