mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #32983 -- Added system check for redundant related_name on symmetrical M2M fields.
Since ManyToManyFields defined with `symmetrical=True` do not add a related field to the target model, including a `related_name` argument will never do what the coder likely expects. This makes including a related_name with a symmetrical model raise a system check warning. ticket-32983
This commit is contained in:
committed by
Carlton Gibson
parent
1fb21ab377
commit
5d4f21b16f
@@ -128,6 +128,20 @@ class RelativeFieldTests(SimpleTestCase):
|
||||
),
|
||||
])
|
||||
|
||||
def test_many_to_many_with_useless_related_name(self):
|
||||
class ModelM2M(models.Model):
|
||||
m2m = models.ManyToManyField('self', related_name='children')
|
||||
|
||||
field = ModelM2M._meta.get_field('m2m')
|
||||
self.assertEqual(ModelM2M.check(), [
|
||||
DjangoWarning(
|
||||
'related_name has no effect on ManyToManyField with '
|
||||
'a symmetrical relationship, e.g. to "self".',
|
||||
obj=field,
|
||||
id='fields.W345',
|
||||
),
|
||||
])
|
||||
|
||||
def test_ambiguous_relationship_model_from(self):
|
||||
class Person(models.Model):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user