Skip to content

Instantly share code, notes, and snippets.

@valerybriz
Created May 2, 2019 21:54
Show Gist options
  • Save valerybriz/56d64d969dc8232f23f1afa5d43b5973 to your computer and use it in GitHub Desktop.
Save valerybriz/56d64d969dc8232f23f1afa5d43b5973 to your computer and use it in GitHub Desktop.
user_queryset = User.objects.all()
# The first hit to the database confirms if at least one object exists.
if user_queryset.exists():
# Another database hit to start fetching the rows in batches.
for user in user_queryset.iterator():
print(user.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment