Django: select_related to a table vs table's field -


i have 2 models

class a(models.model):     val = models.integerfield()  class b(models.model):     val2 = models.integerfield()     = models.foreignkey(a)  class c(models.model):     b = models.foreignkey(b)     val3 = models.integerfield() 

how query -

c.objects.select_related('b').all() 

better -

c.objects.select_related('b__val2').all() 

and if not how query 1 can optimised?

try filter model need, lowcase filter of child models

b.objects.filter(c__isnull=false) 

read more here lookups-that-span-relationships


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -