Code

Ticket #11263: generic_relations_inheritance_order_test.diff

File generic_relations_inheritance_order_test.diff, 1.9 KB (added by tobias, 5 years ago)
Line 
1Index: tests/regressiontests/generic_relations_regress/tests.py
2===================================================================
3--- tests/regressiontests/generic_relations_regress/tests.py    (revision 11527)
4+++ tests/regressiontests/generic_relations_regress/tests.py    (working copy)
5@@ -1,6 +1,6 @@
6 from django.test import TestCase
7 from django.contrib.contenttypes.models import ContentType
8-from models import Link, Place, Restaurant
9+from models import Link, Place, Restaurant, Visitor
10 
11 class GenericRelationTests(TestCase):
12     
13@@ -16,4 +16,11 @@
14         l2 = Link.objects.create(content_object=r)
15         self.assertEqual(list(p.links.all()), [l1])
16         self.assertEqual(list(r.links.all()), [l2])
17-       
18\ No newline at end of file
19+   
20+    def test_inherited_models_order(self):
21+        """
22+        Test for "Bug in lookup with generic relation in model inheritance"
23+       
24+        #11263
25+        """
26+        Visitor.objects.filter(order__status='ordered').count()
27Index: tests/regressiontests/generic_relations_regress/models.py
28===================================================================
29--- tests/regressiontests/generic_relations_regress/models.py   (revision 11527)
30+++ tests/regressiontests/generic_relations_regress/models.py   (working copy)
31@@ -19,4 +19,18 @@
32     
33 class Restaurant(Place):
34     def __unicode__(self):
35-        return "Restaurant: %s" % self.name
36\ No newline at end of file
37+        return "Restaurant: %s" % self.name
38+
39+# models for test_inherited_models_order (#11263)
40+class Order(models.Model):
41+    content_type = models.ForeignKey(ContentType)   
42+    object_id = models.PositiveIntegerField()
43+    content_object = generic.GenericForeignKey()
44+    status = models.CharField(max_length=10, default='ordered')
45+
46+class Person(models.Model):
47+    pass
48+
49+class Visitor(Person):
50+    order = generic.GenericRelation(Order)
51+