summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/admin/checks.py2
-rw-r--r--tests/admin_checks/tests.py17
2 files changed, 18 insertions, 1 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 10d33b06f8..dbbeb7fe9c 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -1130,7 +1130,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
id="admin.E124",
)
]
- elif not field.editable:
+ elif not field.editable or field.primary_key:
return [
checks.Error(
"The value of '%s' refers to '%s', which is not editable "
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
index aa87649dce..4d171ed737 100644
--- a/tests/admin_checks/tests.py
+++ b/tests/admin_checks/tests.py
@@ -363,6 +363,23 @@ class SystemChecksTestCase(SimpleTestCase):
]
self.assertEqual(errors, expected)
+ def test_pk_not_editable(self):
+ # PKs cannot be edited in the list.
+ class SongAdmin(admin.ModelAdmin):
+ list_display = ["title", "id"]
+ list_editable = ["id"]
+
+ errors = SongAdmin(Song, AdminSite()).check()
+ expected = [
+ checks.Error(
+ "The value of 'list_editable[0]' refers to 'id', which is not editable "
+ "through the admin.",
+ obj=SongAdmin,
+ id="admin.E125",
+ )
+ ]
+ self.assertEqual(errors, expected)
+
def test_editable(self):
class SongAdmin(admin.ModelAdmin):
list_display = ["pk", "title"]