Skip to content

Instantly share code, notes, and snippets.

@omerasif57
Created January 30, 2021 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerasif57/9672b87e550f8947cd6116dabae487d8 to your computer and use it in GitHub Desktop.
Save omerasif57/9672b87e550f8947cd6116dabae487d8 to your computer and use it in GitHub Desktop.
When Django QuerySets are evaluated?
When QuerySets are evaluated
You can concatenate as many filters as you like to a QuerySet, and you will not hit the database until the QuerySet is evaluated. QuerySets are only evaluated in the following cases:
The first time you iterate over them
When you slice them, for instance, Post.objects.all()[:3]
When you pickle or cache them
When you call repr() or len() on them
When you explicitly call list() on them
When you test them in a statement, such as bool(), or , and, or if
Source: https://www.oreilly.com/library/view/django-2-by/9781788472487/c0d84fbe-ed96-47e5-b185-cf86335da8d6.xhtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment