diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py index 4b42354d99..7dc3c93b07 100644 --- a/tests/generic_relations/models.py +++ b/tests/generic_relations/models.py @@ -114,6 +114,10 @@ class Rock(Mineral): tags = GenericRelation(TaggedItem) +class ValuableRock(Mineral): + tags = GenericRelation(ValuableTaggedItem) + + class ManualPK(models.Model): id = models.IntegerField(primary_key=True) tags = GenericRelation(TaggedItem, related_query_name='manualpk') diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 72d4d492c6..dab1b8af7c 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -12,7 +12,8 @@ from django.utils import six from .models import ( AllowsNullGFK, Animal, Comparison, ConcreteRelatedModel, ForConcreteModelModel, ForProxyModelModel, Gecko, ManualPK, Mineral, - ProxyRelatedModel, Rock, TaggedItem, ValuableTaggedItem, Vegetable, + ProxyRelatedModel, Rock, TaggedItem, ValuableRock, ValuableTaggedItem, + Vegetable, ) @@ -400,6 +401,13 @@ class GenericRelationsTests(TestCase): ) self.assertEqual(valuedtag.content_object, quartz) + def test_generic_relation_to_inherited_child(self): + # GenericRelations to models that use multi-table inheritance work. + granite = ValuableRock.objects.create(name='granite', hardness=5) + ValuableTaggedItem.objects.create(content_object=granite, tag="countertop", value=1) + granite.delete() # deleting the rock should delete the related tag. + self.assertEqual(ValuableTaggedItem.objects.count(), 0) + def test_generic_inline_formsets(self): GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1) formset = GenericFormSet()