Loading django/db/models/fields/related.py +9 −0 Original line number Diff line number Diff line Loading @@ -1228,6 +1228,15 @@ class ManyToManyField(RelatedField): id='fields.W341', ) ) if self.remote_field.limit_choices_to and self.remote_field.through: warnings.append( checks.Warning( 'limit_choices_to has no effect on ManyToManyField ' 'with a through model.', obj=self, id='fields.W343', ) ) return warnings Loading docs/ref/checks.txt +2 −0 Original line number Diff line number Diff line Loading @@ -251,6 +251,8 @@ Related Fields * **fields.W341**: ``ManyToManyField`` does not support ``validators``. * **fields.W342**: Setting ``unique=True`` on a ``ForeignKey`` has the same effect as using a ``OneToOneField``. * **fields.W343**: ``limit_choices_to`` has no effect on ``ManyToManyField`` with a ``through`` model. Signals ~~~~~~~ Loading tests/invalid_models_tests/test_relative_fields.py +21 −6 Original line number Diff line number Diff line Loading @@ -181,7 +181,18 @@ class RelativeFieldTests(SimpleTestCase): name = models.CharField(max_length=20) class ModelM2M(models.Model): m2m = models.ManyToManyField(Model, null=True, validators=['']) m2m = models.ManyToManyField( Model, null=True, validators=[''], limit_choices_to={'name': 'test_name'}, through='ThroughModel', through_fields=('modelm2m', 'model'), ) class ThroughModel(models.Model): model = models.ForeignKey('Model', models.CASCADE) modelm2m = models.ForeignKey('ModelM2M', models.CASCADE) errors = ModelM2M.check() field = ModelM2M._meta.get_field('m2m') Loading @@ -191,15 +202,19 @@ class RelativeFieldTests(SimpleTestCase): 'null has no effect on ManyToManyField.', obj=field, id='fields.W340', ) ] expected.append( ), DjangoWarning( 'ManyToManyField does not support validators.', obj=field, id='fields.W341', ) ) ), DjangoWarning( 'limit_choices_to has no effect on ManyToManyField ' 'with a through model.', obj=field, id='fields.W343', ), ] self.assertEqual(errors, expected) Loading Loading
django/db/models/fields/related.py +9 −0 Original line number Diff line number Diff line Loading @@ -1228,6 +1228,15 @@ class ManyToManyField(RelatedField): id='fields.W341', ) ) if self.remote_field.limit_choices_to and self.remote_field.through: warnings.append( checks.Warning( 'limit_choices_to has no effect on ManyToManyField ' 'with a through model.', obj=self, id='fields.W343', ) ) return warnings Loading
docs/ref/checks.txt +2 −0 Original line number Diff line number Diff line Loading @@ -251,6 +251,8 @@ Related Fields * **fields.W341**: ``ManyToManyField`` does not support ``validators``. * **fields.W342**: Setting ``unique=True`` on a ``ForeignKey`` has the same effect as using a ``OneToOneField``. * **fields.W343**: ``limit_choices_to`` has no effect on ``ManyToManyField`` with a ``through`` model. Signals ~~~~~~~ Loading
tests/invalid_models_tests/test_relative_fields.py +21 −6 Original line number Diff line number Diff line Loading @@ -181,7 +181,18 @@ class RelativeFieldTests(SimpleTestCase): name = models.CharField(max_length=20) class ModelM2M(models.Model): m2m = models.ManyToManyField(Model, null=True, validators=['']) m2m = models.ManyToManyField( Model, null=True, validators=[''], limit_choices_to={'name': 'test_name'}, through='ThroughModel', through_fields=('modelm2m', 'model'), ) class ThroughModel(models.Model): model = models.ForeignKey('Model', models.CASCADE) modelm2m = models.ForeignKey('ModelM2M', models.CASCADE) errors = ModelM2M.check() field = ModelM2M._meta.get_field('m2m') Loading @@ -191,15 +202,19 @@ class RelativeFieldTests(SimpleTestCase): 'null has no effect on ManyToManyField.', obj=field, id='fields.W340', ) ] expected.append( ), DjangoWarning( 'ManyToManyField does not support validators.', obj=field, id='fields.W341', ) ) ), DjangoWarning( 'limit_choices_to has no effect on ManyToManyField ' 'with a through model.', obj=field, id='fields.W343', ), ] self.assertEqual(errors, expected) Loading