diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-01-09 18:05:57 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-01-11 12:23:23 -0500 |
| commit | bc7d201bdbaeac14a49f51a9ef292d6312b4c45e (patch) | |
| tree | c57fb348dbf867c1639fa1c0be1fbebbbc622d92 /tests/model_fields | |
| parent | 2ed2db2ea3246c7f985ddfbb780850a23e851f9d (diff) | |
Fixed #25858 -- Bound abstract model application relative relationships.
Thanks to Karl Hobley for the report and Markus, Shai, Aymeric for their input
and Tim for the review.
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/tests.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 14b56139de..9a27dd4670 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -251,6 +251,25 @@ class ForeignKeyTests(test.TestCase): "Pending lookup added for a foreign key on an abstract model" ) + @isolate_apps('model_fields', 'model_fields.tests') + def test_abstract_model_app_relative_foreign_key(self): + class Refered(models.Model): + class Meta: + app_label = 'model_fields' + + class AbstractReferent(models.Model): + reference = models.ForeignKey('Refered', on_delete=models.CASCADE) + + class Meta: + app_label = 'model_fields' + abstract = True + + class ConcreteReferent(AbstractReferent): + class Meta: + app_label = 'tests' + + self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) + class ManyToManyFieldTests(test.SimpleTestCase): def test_abstract_model_pending_operations(self): @@ -273,6 +292,30 @@ class ManyToManyFieldTests(test.SimpleTestCase): "Pending lookup added for a many-to-many field on an abstract model" ) + @isolate_apps('model_fields', 'model_fields.tests') + def test_abstract_model_app_relative_foreign_key(self): + class Refered(models.Model): + class Meta: + app_label = 'model_fields' + + class Through(models.Model): + refered = models.ForeignKey('Refered', on_delete=models.CASCADE) + referent = models.ForeignKey('tests.ConcreteReferent', on_delete=models.CASCADE) + + class AbstractReferent(models.Model): + reference = models.ManyToManyField('Refered', through='Through') + + class Meta: + app_label = 'model_fields' + abstract = True + + class ConcreteReferent(AbstractReferent): + class Meta: + app_label = 'tests' + + self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) + self.assertEqual(ConcreteReferent.reference.through, Through) + class TextFieldTests(test.TestCase): def test_to_python(self): |
