Fixed #19939 -- generic relations + split_exclude regression

Added a test, the issue was already fixed (likely by the patch
for #19385).
This commit is contained in:
Anssi Kääriäinen 2013-05-11 03:48:58 +03:00
parent 92351c74c1
commit c0d8932a6d
2 changed files with 10 additions and 1 deletions

View File

@ -98,3 +98,7 @@ class Gecko(models.Model):
# To test fix for #11263 # To test fix for #11263
class Rock(Mineral): class Rock(Mineral):
tags = generic.GenericRelation(TaggedItem) tags = generic.GenericRelation(TaggedItem)
class ManualPK(models.Model):
id = models.IntegerField(primary_key=True)
tags = generic.GenericRelation(TaggedItem)

View File

@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType
from django.test import TestCase from django.test import TestCase
from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
Vegetable, Mineral, Gecko, Rock) Vegetable, Mineral, Gecko, Rock, ManualPK)
class GenericRelationsTests(TestCase): class GenericRelationsTests(TestCase):
@ -75,12 +75,17 @@ class GenericRelationsTests(TestCase):
"<Animal: Lion>", "<Animal: Lion>",
"<Animal: Platypus>" "<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'), [ self.assertQuerysetEqual(Animal.objects.filter(tags__tag='fatty'), [
"<Animal: Platypus>" "<Animal: Platypus>"
]) ])
self.assertQuerysetEqual(Animal.objects.exclude(tags__tag='fatty'), [ self.assertQuerysetEqual(Animal.objects.exclude(tags__tag='fatty'), [
"<Animal: Lion>" "<Animal: Lion>"
]) ])
mpk.delete()
# If you delete an object with an explicit Generic relation, the related # If you delete an object with an explicit Generic relation, the related
# objects are deleted when the source object is deleted. # objects are deleted when the source object is deleted.