Skip to content

Instantly share code, notes, and snippets.

@valerybriz
Created April 7, 2019 00:38
Show Gist options
  • Select an option

  • Save valerybriz/dda05ed09e91ec1e76b49573dc180565 to your computer and use it in GitHub Desktop.

Select an option

Save valerybriz/dda05ed09e91ec1e76b49573dc180565 to your computer and use it in GitHub Desktop.
cached and not cached queries
# Create the query filtering users with email [email protected]
users = User.objects.get(email="[email protected]")
users.name # Hit the database and retrive the name value
users.name # cached version, no database access
# Create the query filtering teams named tigers
team = Team.objects.get(name="tigers")
team.users.all() # query performed
team.users.all() # query performed again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment