Ticket #11263: generic_relations_inheritance_order_test.diff

File generic_relations_inheritance_order_test.diff, 1.9 KB (added by Tobias McNulty, 15 years ago)
  • tests/regressiontests/generic_relations_regress/tests.py

     
    11from django.test import TestCase
    22from django.contrib.contenttypes.models import ContentType
    3 from models import Link, Place, Restaurant
     3from models import Link, Place, Restaurant, Visitor
    44
    55class GenericRelationTests(TestCase):
    66   
     
    1616        l2 = Link.objects.create(content_object=r)
    1717        self.assertEqual(list(p.links.all()), [l1])
    1818        self.assertEqual(list(r.links.all()), [l2])
    19        
    20  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()
  • tests/regressiontests/generic_relations_regress/models.py

     
    1919   
    2020class Restaurant(Place):
    2121    def __unicode__(self):
    22         return "Restaurant: %s" % self.name
    23  No newline at end of file
     22        return "Restaurant: %s" % self.name
     23
     24# models for test_inherited_models_order (#11263)
     25class Order(models.Model):
     26    content_type = models.ForeignKey(ContentType)   
     27    object_id = models.PositiveIntegerField()
     28    content_object = generic.GenericForeignKey()
     29    status = models.CharField(max_length=10, default='ordered')
     30
     31class Person(models.Model):
     32    pass
     33
     34class Visitor(Person):
     35    order = generic.GenericRelation(Order)
     36   
Back to Top