From c61219a7ae051d2baab53f041e00592011fc550c Mon Sep 17 00:00:00 2001 From: Bakdolot <80908236+Bakdolot@users.noreply.github.com> Date: Tue, 2 May 2023 10:46:22 +0600 Subject: Fixed #34513 -- Added system check for relational fields in ModelAdmin.list_display. --- tests/modeladmin/test_checks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/modeladmin') diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index 85f2eda69e..69aa242a64 100644 --- a/tests/modeladmin/test_checks.py +++ b/tests/modeladmin/test_checks.py @@ -554,6 +554,30 @@ class ListDisplayTests(CheckTestCase): "admin.E109", ) + def test_invalid_related_field(self): + class TestModelAdmin(ModelAdmin): + list_display = ["song"] + + self.assertIsInvalid( + TestModelAdmin, + Band, + "The value of 'list_display[0]' must not be a many-to-many field or a " + "reverse foreign key.", + "admin.E109", + ) + + def test_invalid_m2m_related_name(self): + class TestModelAdmin(ModelAdmin): + list_display = ["featured"] + + self.assertIsInvalid( + TestModelAdmin, + Band, + "The value of 'list_display[0]' must not be a many-to-many field or a " + "reverse foreign key.", + "admin.E109", + ) + def test_valid_case(self): @admin.display def a_callable(obj): -- cgit v1.3