diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index 515cedcf69..f768374d54 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -791,6 +791,8 @@ class ModelAdminChecks(BaseModelAdminChecks): id='admin.E126', ) ] + else: + return [] def _check_search_fields(self, cls, model): """ Check search_fields is a sequence. """ diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index 934e3f391e..c0ce428e67 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -52,6 +52,30 @@ class SystemChecksTestCase(TestCase): def test_readonly_and_editable(self): class SongAdmin(admin.ModelAdmin): readonly_fields = ["original_release"] + list_display = ["pk", "original_release"] + list_editable = ["original_release"] + fieldsets = [ + (None, { + "fields": ["title", "original_release"], + }), + ] + + errors = SongAdmin.check(model=Song) + expected = [ + checks.Error( + ('"list_editable[0]" refers to field "original_release", ' + 'whih is not editable through the admin.'), + hint=None, + obj=SongAdmin, + id='admin.E126', + ) + ] + self.assertEqual(errors, expected) + + def test_editable(self): + class SongAdmin(admin.ModelAdmin): + list_display = ["pk", "title"] + list_editable = ["title"] fieldsets = [ (None, { "fields": ["title", "original_release"],