Lets say I have the following:
class Model1(Model):
field1 = ForeignKey(Model2)
query_field = IntegerField()
class Model2(Model):
field2 = ForeignKey(Model3)
class Model3(Model)
field3 = SomeDesiredValue
Now I want to do a query on the Model1
table and pull out field3
from Model3
. My question is on performance of select_related
.
If I do
query = Model1.objects.filter(query_field=filter_paramter).select_related('field1')
I'm assuming the following will still hit the database?
query[0].field1.field2.field3
Can I do the following to make it faster?
query = Model1.objects.filter(query_field=filter_paramter).select_related('field1__field2')