Skip to content

Instantly share code, notes, and snippets.

@valerybriz
Last active May 2, 2019 21:51
Show Gist options
  • Save valerybriz/2260b1a7907a334e027de1159aca8ee4 to your computer and use it in GitHub Desktop.
Save valerybriz/2260b1a7907a334e027de1159aca8ee4 to your computer and use it in GitHub Desktop.
queries that hit the database
# Iteration
for user in User.objects.all():
print(user.name)
# Slicing
User.objects.all()[:10]
# Pickling or Caching
pickle_str = pickle.dumps(user_queryset)
user_queryset = pickle.loads(pickle_str)
len(user_queryset._result_cache)
# Methods like repr(), len(), list(), bool()
user_list = list(User.objects.all())
# or a boolean condition like:
if User.objects.filter(name="Ana"):
print("There is at least one user who's name is Ana")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment