summaryrefslogtreecommitdiff
path: root/tests/modeladmin
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-27 20:36:22 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-27 20:37:23 +0100
commit9a182f3d959d16354e24f34713df602f1bef6556 (patch)
tree86352be1fed09f17043600a2cea57eb384637f6e /tests/modeladmin
parent9aad44150fa7632b894c8b1d1cb9c6dde131b577 (diff)
[5.0.x] Fixed #35056 -- Fixed system check crash on reverse m2m relations with related_name in ModelAdmin.filter_horizontal/vertical.
Thanks Thomas Feldmann for the report. Regression in 107865780aa44914e21d27fdf4ca269bc61c7f01. Backport of 751d732a3815a68bdb5b7aceda0e7d5981362c4a from main
Diffstat (limited to 'tests/modeladmin')
-rw-r--r--tests/modeladmin/test_checks.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py
index 2ed27f8a3d..85c175d581 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")