Skip to content

Instantly share code, notes, and snippets.

@kyle-eshares
Created October 17, 2016 20:02
Show Gist options
  • Save kyle-eshares/5c90bc1a98aeadee6ff3b3de97303c50 to your computer and use it in GitHub Desktop.
Save kyle-eshares/5c90bc1a98aeadee6ff3b3de97303c50 to your computer and use it in GitHub Desktop.
# Don't waste a query if you are using the queryset
books = Book.objects.filter(..)
if books:
do_stuff_with_books(books)
# If you aren't using the queryset use exist
books = Book.objects.filter(..)
if books.exists():
do_some_stuff()
# But never
if Book.objects.filter(..):
do_some_stuff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment