Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goutomroy/dd2340a587a35b68a193f5fc33568761 to your computer and use it in GitHub Desktop.
Save goutomroy/dd2340a587a35b68a193f5fc33568761 to your computer and use it in GitHub Desktop.
# Don't. Needs database hit
blog_id = Entry.objects.get(id=200).blog.id
# Do. The foreign key is already cached, so no database hit
blog_id = Entry.objects.get(id=200).blog_id
# Do. No database hit
blog_id = Entry.objects.select_related('blog').get(id=200).blog.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment