[Answered ]-Does Django requery every time I access a related model?

2๐Ÿ‘

โœ…

No. Once you have accessed it the first time, the related entity will be cached and subsequent lookups will not hit the db again.

Note though that this is a per-object cache: if for any reason you re-fetch the Foo instance, the cache will be lost and a call to bar will cause another query.

Also note that you can eliminate the extra call altogether by using select_related when you query Foo in the first place.

๐Ÿ‘คDaniel Roseman

Leave a comment