Ticket #11263: generic_relations_inheritance_order_test.2.diff
File generic_relations_inheritance_order_test.2.diff, 2.9 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/generic_relations_regress/tests.py
70 70 Q(notes__note__icontains=r'other note')) 71 71 self.assertTrue(org_contact in qs) 72 72 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() 73 81 82 photo_order = Order.objects.create(content_object=photo, status='ordered') 83 media_order = Order.objects.create(content_object=media, status='ordered') 74 84 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
4 4 5 5 __all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address', 6 6 'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2', 7 'Contact', 'Organization', 'Note' )7 'Contact', 'Organization', 'Note', 'Photo', 'Order', 'Media') 8 8 9 9 class Link(models.Model): 10 10 content_type = models.ForeignKey(ContentType) … … 77 77 name = models.CharField(max_length=255) 78 78 contacts = models.ManyToManyField(Contact, related_name='organizations') 79 79 80 # models for test_inherited_models_order (#11263) 81 class 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 87 class Media(models.Model): 88 order = generic.GenericRelation(Order) 89 90 class Photo(Media): 91 pass