

def test_deep_select_related_from_translated_field(self):
    with translation.override('en'):
        with self.assertNumQueries(1):
            qs = RelatedRelated.objects.language().select_related('trans_related__normal', 'trans_simple__normal')
            self.assertCountEqual((obj.pk for obj in qs), (self.relrel1.pk, self.relrel2.pk))
        with self.assertNumQueries(0):
            for obj in qs:
                if (obj.pk == self.relrel1.pk):
                    self.assertEqual(obj.trans_related.pk, self.related2.pk)
                    self.assertEqual(obj.trans_related.normal.pk, self.normal_id[2])
                    self.assertEqual(obj.trans_related.normal.translated_field, NORMAL[2].translated_field['en'])
                    self.assertEqual(obj.trans_simple, None)
                if (obj.pk == self.relrel2.pk):
                    self.assertEqual(obj.trans_related.pk, self.related1.pk)
                    self.assertEqual(obj.trans_related.normal.pk, self.normal_id[1])
                    self.assertEqual(obj.trans_related.normal.translated_field, NORMAL[1].translated_field['en'])
                    self.assertEqual(obj.trans_simple.pk, self.simplerel.pk)
                    self.assertEqual(obj.trans_simple.translated_field, self.simplerel.translated_field)
                    self.assertEqual(obj.trans_simple.normal.pk, self.normal_id[1])
                    self.assertEqual(obj.trans_simple.normal.translated_field, NORMAL[1].translated_field['en'])

dataset/ETHPy150Open KristianOellegaard/django-hvad/hvad/tests/related.py DeepSelectRelatedTests.test_deep_select_related_from_translated_field/original