Ticket #21848: 21848-test.diff

File 21848-test.diff, 1.6 KB (added by Tim Graham, 11 years ago)
  • tests/select_related_onetoone/models.py

    diff --git a/tests/select_related_onetoone/models.py b/tests/select_related_onetoone/models.py
    index 9af1b3f..6b10666 100644
    a b class Child3(Child2):  
    102102
    103103class Child4(Child1):
    104104    value4 = models.IntegerField()
     105
     106
     107class MyProduct(models.Model):
     108    id = models.AutoField(primary_key=True)
     109    price = models.IntegerField(db_column='price', default=0)
     110
     111    class Meta:
     112        db_table = 'product'
     113
     114class CurrentProduct(Product):
     115    parent_product = models.OneToOneField(MyProduct, parent_link=True, related_name='current_product', db_column='parent')
     116    price_test = models.IntegerField(default=0, db_column='price_frame')
     117
     118    class Meta:
     119        db_table = 'door'
  • tests/select_related_onetoone/tests.py

    diff --git a/tests/select_related_onetoone/tests.py b/tests/select_related_onetoone/tests.py
    index 92896b4..7130f88 100644
    a b class ReverseSelectRelatedTestCase(TestCase):  
    208208            self.assertEqual(p.child1.name1, 'n1')
    209209        with self.assertNumQueries(1):
    210210            self.assertEqual(p.child1.child4.name1, 'n1')
     211
     212    def test_product(self):
     213        from .models import MyProduct, CurrentProduct
     214        myproduct = MyProduct.objects.create(price=1)
     215        CurrentProduct.objects.create(parent_product=myproduct, price_test=0)
     216        products = MyProduct.objects.select_related('current_product').all()
     217        self.assertEqual(products[0].current_product.price_test, 0)
Back to Top