Skip to content

Instantly share code, notes, and snippets.

@valerybriz
Created April 7, 2019 00:38
Show Gist options
  • Save valerybriz/dda05ed09e91ec1e76b49573dc180565 to your computer and use it in GitHub Desktop.
Save valerybriz/dda05ed09e91ec1e76b49573dc180565 to your computer and use it in GitHub Desktop.
cached and not cached queries
# Create the query filtering users with email myemail@gmail.com
users = User.objects.get(email="myemail@gmail.com")
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