

def test_select_related(self):
    with translation.override('en'):
        SimpleRelated.objects.language().create(normal=self.normal2, translated_field='test2')
        with self.assertNumQueries(1):
            rel_objects = SimpleRelated.objects.language().select_related('normal').order_by('normal__shared_field')
            check = [(NORMAL[1].shared_field, NORMAL[1].translated_field['en']), (NORMAL[2].shared_field, NORMAL[2].translated_field['en'])]
            self.assertEqual(list(((obj.normal.shared_field, obj.normal.translated_field) for obj in rel_objects)), check)

dataset/ETHPy150Open KristianOellegaard/django-hvad/hvad/tests/related.py SelectRelatedTests.test_select_related/original