

def test_nullable_relation(self):
    im = Image.objects.create(name='imag1')
    p1 = Product.objects.create(name='Django Plushie', image=im)
    p2 = Product.objects.create(name='Talking Django Plushie')
    with self.assertNumQueries(1):
        result = sorted(Product.objects.select_related('image'), key=(lambda x: x.name))
        self.assertEqual([p.name for p in result], ['Django Plushie', 'Talking Django Plushie'])
        self.assertEqual(p1.image, im)
        self.assertIsNone(p2.image)

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