summaryrefslogtreecommitdiff
path: root/tests/generic_relations
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-10-08 09:15:28 -0400
committerTim Graham <timograham@gmail.com>2015-10-08 14:47:35 -0400
commit4a7b58210defea33a428b748ccbc97ae8fd49838 (patch)
tree9d802e11a8b74def70a547f84d5a7ba5a6814b06 /tests/generic_relations
parent25f287f6b2f677213605364c33bb37f33feac953 (diff)
downloaddjango-4a7b58210defea33a428b748ccbc97ae8fd49838.tar.gz
Refs #19722 -- Added a test for querying generic relations of a parent class.
Fixed in c9a96075fa02b6d52bec748ffdfb413688a15774.
Diffstat (limited to 'tests/generic_relations')
-rw-r--r--tests/generic_relations/models.py4
-rw-r--r--tests/generic_relations/tests.py13
2 files changed, 15 insertions, 2 deletions
diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py
index 7dc3c93b07..7522f5b4cd 100644
--- a/tests/generic_relations/models.py
+++ b/tests/generic_relations/models.py
@@ -88,6 +88,10 @@ class Vegetable(models.Model):
return self.name
+class Carrot(Vegetable):
+ pass
+
+
@python_2_unicode_compatible
class Mineral(models.Model):
name = models.CharField(max_length=150)
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index dab1b8af7c..8beee7242a 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -10,7 +10,7 @@ from django.test import SimpleTestCase, TestCase
from django.utils import six
from .models import (
- AllowsNullGFK, Animal, Comparison, ConcreteRelatedModel,
+ AllowsNullGFK, Animal, Carrot, Comparison, ConcreteRelatedModel,
ForConcreteModelModel, ForProxyModelModel, Gecko, ManualPK, Mineral,
ProxyRelatedModel, Rock, TaggedItem, ValuableRock, ValuableTaggedItem,
Vegetable,
@@ -488,7 +488,16 @@ id="id_generic_relations-taggeditem-content_type-object_id-1-id" /></p>""" % tag
"""
granite = Rock.objects.create(name='granite', hardness=5)
TaggedItem.objects.create(content_object=granite, tag="countertop")
- self.assertEqual(Rock.objects.filter(tags__tag="countertop").count(), 1)
+ self.assertEqual(Rock.objects.get(tags__tag="countertop"), granite)
+
+ def test_subclasses_with_parent_gen_rel(self):
+ """
+ Generic relations on a base class (Vegetable) work correctly in
+ subclasses (Carrot).
+ """
+ bear = Carrot.objects.create(name='carrot')
+ TaggedItem.objects.create(content_object=bear, tag='orange')
+ self.assertEqual(Carrot.objects.get(tags__tag='orange'), bear)
def test_generic_inline_formsets_initial(self):
"""