Skip to content

Instantly share code, notes, and snippets.

@goutomroy
Last active June 7, 2019 17:07
Show Gist options
  • Save goutomroy/ddceafd847d5218b1da7af6b8515f73f to your computer and use it in GitHub Desktop.
Save goutomroy/ddceafd847d5218b1da7af6b8515f73f to your computer and use it in GitHub Desktop.
# The following will create two QuerySet's, evaluate them, and throw them away
# because they are not saving the queryset anywhere to reuse them later.
print([e.headline for e in Entry.objects.all()])
print([e.pub_date for e in Entry.objects.all()])
# Following code saves QuerySet in a variable. When it evaluates,
# it saves the results to its cache(_result_cache).
queryset = Entry.objects.all()
# evaluation with iteration.
for each in queryset:
print(each.headline)
# Using cache from previous evaluation.
for each in queryset:
print(each.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment