Loading tests/generic_relations/models.py +4 −0 Original line number Diff line number Diff line Loading @@ -98,3 +98,7 @@ class Gecko(models.Model): # To test fix for #11263 class Rock(Mineral): tags = generic.GenericRelation(TaggedItem) class ManualPK(models.Model): id = models.IntegerField(primary_key=True) tags = generic.GenericRelation(TaggedItem) tests/generic_relations/tests.py +6 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, Vegetable, Mineral, Gecko, Rock) Vegetable, Mineral, Gecko, Rock, ManualPK) class GenericRelationsTests(TestCase): Loading Loading @@ -75,12 +75,17 @@ class GenericRelationsTests(TestCase): "<Animal: Lion>", "<Animal: Platypus>" ]) # Create another fatty tagged instance with different PK to ensure # there is a content type restriction in the generated queries below. mpk = ManualPK.objects.create(id=lion.pk) mpk.tags.create(tag="fatty") self.assertQuerysetEqual(Animal.objects.filter(tags__tag='fatty'), [ "<Animal: Platypus>" ]) self.assertQuerysetEqual(Animal.objects.exclude(tags__tag='fatty'), [ "<Animal: Lion>" ]) mpk.delete() # If you delete an object with an explicit Generic relation, the related # objects are deleted when the source object is deleted. Loading Loading
tests/generic_relations/models.py +4 −0 Original line number Diff line number Diff line Loading @@ -98,3 +98,7 @@ class Gecko(models.Model): # To test fix for #11263 class Rock(Mineral): tags = generic.GenericRelation(TaggedItem) class ManualPK(models.Model): id = models.IntegerField(primary_key=True) tags = generic.GenericRelation(TaggedItem)
tests/generic_relations/tests.py +6 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, Vegetable, Mineral, Gecko, Rock) Vegetable, Mineral, Gecko, Rock, ManualPK) class GenericRelationsTests(TestCase): Loading Loading @@ -75,12 +75,17 @@ class GenericRelationsTests(TestCase): "<Animal: Lion>", "<Animal: Platypus>" ]) # Create another fatty tagged instance with different PK to ensure # there is a content type restriction in the generated queries below. mpk = ManualPK.objects.create(id=lion.pk) mpk.tags.create(tag="fatty") self.assertQuerysetEqual(Animal.objects.filter(tags__tag='fatty'), [ "<Animal: Platypus>" ]) self.assertQuerysetEqual(Animal.objects.exclude(tags__tag='fatty'), [ "<Animal: Lion>" ]) mpk.delete() # If you delete an object with an explicit Generic relation, the related # objects are deleted when the source object is deleted. Loading