Created
January 30, 2021 12:32
-
-
Save omerasif57/9672b87e550f8947cd6116dabae487d8 to your computer and use it in GitHub Desktop.
When Django QuerySets are evaluated?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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