Last active
May 2, 2019 21:51
-
-
Save valerybriz/2260b1a7907a334e027de1159aca8ee4 to your computer and use it in GitHub Desktop.
queries that hit the database
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
# 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