

def test_inheritance_deferred2(self):
    c = Child4.objects.create(name1='n1', name2='n2', value=1, value4=4)
    qs = Parent2.objects.select_related('child1', 'child1__child4').only('id2', 'child1__value', 'child1__child4__value4')
    with self.assertNumQueries(1):
        p = qs.get(name2='n2')
        self.assertEqual(p.id2, c.id2)
        self.assertEqual(p.child1.value, 1)
        self.assertEqual(p.child1.child4.value4, 4)
        self.assertEqual(p.child1.child4.id2, c.id2)
    p = qs.get(name2='n2')
    with self.assertNumQueries(1):
        self.assertEqual(p.child1.name2, 'n2')
    p = qs.get(name2='n2')
    with self.assertNumQueries(0):
        self.assertEqual(p.child1.name1, 'n1')
        self.assertEqual(p.child1.child4.name1, 'n1')

dataset/ETHPy150Open django/django/tests/select_related_onetoone/tests.py ReverseSelectRelatedTestCase.test_inheritance_deferred2/original