From 58c7ff39fb265754fb17ab8d7f8a1401b355777b Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 2 Oct 2015 14:28:15 -0400 Subject: [PATCH] Refs #13203, #9501 -- Added a test for generic relations to child models. Fixed in 97774429aeb54df4c09895c07cd1b09e70201f7d. --- tests/generic_relations/models.py | 4 ++++ tests/generic_relations/tests.py | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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()