Refs #13203, #9501 -- Added a test for generic relations to child models.

Fixed in 97774429ae.
This commit is contained in:
Tim Graham 2015-10-02 14:28:15 -04:00
parent ac09d22f79
commit 58c7ff39fb
2 changed files with 13 additions and 1 deletions

View File

@ -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')

View File

@ -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()