diff options
Diffstat (limited to 'tests/modeladmin')
| -rw-r--r-- | tests/modeladmin/test_checks.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index 47b1b40ed7..73777f05ab 100644 --- a/tests/modeladmin/test_checks.py +++ b/tests/modeladmin/test_checks.py @@ -323,6 +323,24 @@ class FilterVerticalCheckTests(CheckTestCase): ) @isolate_apps("modeladmin") + def test_invalid_reverse_m2m_field_with_related_name(self): + class Contact(Model): + pass + + class Customer(Model): + contacts = ManyToManyField("Contact", related_name="customers") + + class TestModelAdmin(ModelAdmin): + filter_vertical = ["customers"] + + self.assertIsInvalid( + TestModelAdmin, + Contact, + "The value of 'filter_vertical[0]' must be a many-to-many field.", + "admin.E020", + ) + + @isolate_apps("modeladmin") def test_invalid_m2m_field_with_through(self): class Artist(Model): bands = ManyToManyField("Band", through="BandArtist") @@ -385,6 +403,24 @@ class FilterHorizontalCheckTests(CheckTestCase): ) @isolate_apps("modeladmin") + def test_invalid_reverse_m2m_field_with_related_name(self): + class Contact(Model): + pass + + class Customer(Model): + contacts = ManyToManyField("Contact", related_name="customers") + + class TestModelAdmin(ModelAdmin): + filter_horizontal = ["customers"] + + self.assertIsInvalid( + TestModelAdmin, + Contact, + "The value of 'filter_horizontal[0]' must be a many-to-many field.", + "admin.E020", + ) + + @isolate_apps("modeladmin") def test_invalid_m2m_field_with_through(self): class Artist(Model): bands = ManyToManyField("Band", through="BandArtist") |
