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 14:08:50 -0500 |
| commit | 27ef6403c8b9f332feb1f9fe52053ded0b91da85 (patch) | |
| tree | 84749120ce9da4be7d83b9c66df2641b4bb0db72 /tests/model_fields/tests.py | |
| parent | 76b4015ea9b02fdbc3acebe71ed79bcc902697da (diff) | |
[1.9.x] 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.
Backport of bc7d201bdbaeac14a49f51a9ef292d6312b4c45e from master
Diffstat (limited to 'tests/model_fields/tests.py')
| -rw-r--r-- | tests/model_fields/tests.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 34793eacdb..5aafdb2844 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -7,6 +7,7 @@ from decimal import Decimal from django import forms, test from django.apps import apps +from django.apps.registry import Apps from django.core import checks, validators from django.core.exceptions import ValidationError from django.db import IntegrityError, connection, models, transaction @@ -247,6 +248,28 @@ class ForeignKeyTests(test.TestCase): "Pending lookup added for a foreign key on an abstract model" ) + def test_abstract_model_app_relative_foreign_key(self): + test_apps = Apps(['model_fields', 'model_fields.tests']) + + class Refered(models.Model): + class Meta: + apps = test_apps + 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: + apps = test_apps + app_label = 'tests' + + self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) + class ManyToManyFieldTests(test.SimpleTestCase): def test_abstract_model_pending_operations(self): @@ -269,6 +292,37 @@ class ManyToManyFieldTests(test.SimpleTestCase): "Pending lookup added for a many-to-many field on an abstract model" ) + def test_abstract_model_app_relative_foreign_key(self): + test_apps = Apps(['model_fields', 'model_fields.tests']) + + class Refered(models.Model): + class Meta: + apps = test_apps + 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 Meta: + apps = test_apps + app_label = 'model_fields' + + class AbstractReferent(models.Model): + reference = models.ManyToManyField('Refered', through='Through') + + class Meta: + app_label = 'model_fields' + abstract = True + + class ConcreteReferent(AbstractReferent): + class Meta: + apps = test_apps + 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): |
