From c813fb327cb1b09542be89c5ceed367826236bc2 Mon Sep 17 00:00:00 2001 From: Bakdolot <80908236+Bakdolot@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:14:35 +0600 Subject: Fixed #34481 -- Added system check for reverse related fields in ModelAdmin.list_display. --- django/contrib/admin/checks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index 27537d9614..0fefe65e48 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -916,10 +916,13 @@ class ModelAdminChecks(BaseModelAdminChecks): id="admin.E108", ) ] - if isinstance(field, models.ManyToManyField): + if isinstance(field, models.ManyToManyField) or ( + getattr(field, "rel", None) and field.rel.field.many_to_one + ): return [ checks.Error( - "The value of '%s' must not be a ManyToManyField." % label, + f"The value of '{label}' must not be a many-to-many field or a " + f"reverse foreign key.", obj=obj.__class__, id="admin.E109", ) -- cgit v1.2.1