python - Django How to make only one query with queryset exists method? -
i try understand django documentation queryset exists method
additionally, if some_queryset has not yet been evaluated, know @ point, using some_queryset.exists() more overall work (one query existence check plus 1 later retrieve results) using bool(some_queryset), retrieves results , checks if returned.
what i'm doing:
if queryset.exists(): do_something() element in queryset: do_something_else(element)
so i'm doing more overall work using bool(some_queryset)
does code makes 1 query?
if bool(queryset): do_something() element in queryset: do_something_else(element)
if yes python puts results ? in queryset variable ?
thank you
from .exists()
docs itself:
additionally, if
some_queryset
has not yet been evaluated, know @ point, usingsome_queryset.exists()
more overall work (one query existence check plus 1 later retrieve results) usingbool(some_queryset)
, retrieves results , checks if returned.
the results of evaluated queryset
cached django. so, whenever data required queryset cached results used.
related docs: caching , querysets
Comments
Post a Comment