I have 2 models
class A(models.Model):
val = models.IntegerField()
class B(models.Model):
val2 = models.IntegerField()
a = models.ForeignKey(A)
class C(models.Model):
b = models.ForeignKey(B)
val3 = models.IntegerField()
How is the query -
C.objects.select_related('B').all()
better than -
C.objects.select_related('B__val2').all()
And if not how query one can be optimised?
Try to filter model you need, by lowcase filter of the child models
read more here lookups-that-span-relationships