Last active
October 17, 2016 20:05
-
-
Save kyle-eshares/fb5d95d4111902d590c869d68c67cc29 to your computer and use it in GitHub Desktop.
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
# Don't waste a query if you are using the queryset | |
books = Book.objects.filter(..) | |
if len(books) > 5: | |
do_stuff_with_books(books) | |
# If you aren't using the queryset use count | |
books = Book.objects.filter(..) | |
if books.count() > 5: | |
do_some_stuff() | |
# But never | |
if len(Book.objects.filter(..)) > 5: | |
do_some_stuff() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment