diff options
| author | Simon Willison <simonw@eventbrite.com> | 2018-07-18 15:21:40 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-08-22 12:07:29 -0400 |
| commit | 586a9dc4295357de1f5ad0590ad34bf2bc008f79 (patch) | |
| tree | c416257a9176de603d79b12f1f99e28c72725735 /tests | |
| parent | f2d5dafec93e6b3100f004c559ebe21e2b783ae7 (diff) | |
Fixed #26352 -- Made system check allow ManyToManyField to target the same model if through_fields differs.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 9dd2fd1f06..709d73d6c8 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -771,13 +771,35 @@ class OtherModelTests(SimpleTestCase): self.assertEqual(Group.check(), [ Error( - "The model has two many-to-many relations through " + "The model has two identical many-to-many relations through " "the intermediate model 'invalid_models_tests.Membership'.", obj=Group, id='models.E003', ) ]) + def test_two_m2m_through_same_model_with_different_through_fields(self): + class Country(models.Model): + pass + + class ShippingMethod(models.Model): + to_countries = models.ManyToManyField( + Country, through='ShippingMethodPrice', + through_fields=('method', 'to_country'), + ) + from_countries = models.ManyToManyField( + Country, through='ShippingMethodPrice', + through_fields=('method', 'from_country'), + related_name='+', + ) + + class ShippingMethodPrice(models.Model): + method = models.ForeignKey(ShippingMethod, models.CASCADE) + to_country = models.ForeignKey(Country, models.CASCADE) + from_country = models.ForeignKey(Country, models.CASCADE) + + self.assertEqual(ShippingMethod.check(), []) + def test_missing_parent_link(self): msg = 'Add parent_link=True to invalid_models_tests.ParkingLot.parent.' with self.assertRaisesMessage(ImproperlyConfigured, msg): |
