Ticket #11263: generic_relations_inheritance_order_test.2.diff

File generic_relations_inheritance_order_test.2.diff, 2.9 KB (added by amarkor, 4 years ago)

updated test

  • tests/regressiontests/generic_relations_regress/tests.py

     
    7070            Q(notes__note__icontains=r'other note'))
    7171        self.assertTrue(org_contact in qs)
    7272
     73    def test_inherited_models_order(self):
     74        """
     75        Test for "Bug in lookup with generic relation in model inheritance"
     76       
     77        #11263
     78        """
     79        media = Media.objects.create()
     80        photo = Photo.objects.create()
    7381
     82        photo_order = Order.objects.create(content_object=photo, status='ordered')
     83        media_order = Order.objects.create(content_object=media, status='ordered')
    7484
     85        # add some other orders to the db
     86        Order.objects.create(content_object=media, status='ordered')
     87        Order.objects.create(content_object=media, status='ordered')
     88
     89        Order.objects.create(content_object=photo, status='ordered')
     90        Order.objects.create(content_object=photo, status='ordered')
     91        Order.objects.create(content_object=photo, status='ordered')
     92
     93#        print photo.order.filter(status='ordered').query,
     94#        print Photo.objects.filter(order__status='ordered').query
     95
     96        self.assertEqual(7, Order.objects.filter(status='ordered').count())
     97
     98        self.assertEqual(media.order.filter(status='ordered').count(),
     99                         Media.objects.filter(order__status='ordered').count())
     100
     101        self.assertEqual(photo.order.filter(status='ordered').count(),
     102                         Photo.objects.filter(order__status='ordered').count())
  • tests/regressiontests/generic_relations_regress/models.py

     
    44
    55__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
    66           'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
    7            'Contact', 'Organization', 'Note')
     7           'Contact', 'Organization', 'Note', 'Photo', 'Order', 'Media')
    88
    99class Link(models.Model):
    1010    content_type = models.ForeignKey(ContentType)
     
    7777    name = models.CharField(max_length=255)
    7878    contacts = models.ManyToManyField(Contact, related_name='organizations')
    7979
     80# models for test_inherited_models_order (#11263)
     81class Order(models.Model):
     82    content_type = models.ForeignKey(ContentType)   
     83    object_id = models.PositiveIntegerField()
     84    content_object = generic.GenericForeignKey()
     85    status = models.CharField(max_length=10, default='ordered')
     86
     87class Media(models.Model):
     88    order = generic.GenericRelation(Order)
     89
     90class Photo(Media):
     91    pass
Back to Top