goh
goh

Reputation: 29511

django query select_related()

I got a question concerning select_related(). Assuming I do not specify the depth nor the attributes i.e items = ModelA.objects.selected_related(), does it work for reverse relationship i.e items[0].fk_set?

Also, if we pass items into context and use it inside the django templates, will accessing the foreign keys of items inside the template hit the database?

Upvotes: 0

Views: 448

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

It doesn't work for reverse relationship, there will be additional database hit. You can easily check it yourself with debug_tolbar.

There is no difference where to evaluate queryset: in view or in template.

Upvotes: 2

Related Questions