Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erickgnavar/fe9a1805b87365f25252 to your computer and use it in GitHub Desktop.
Save erickgnavar/fe9a1805b87365f25252 to your computer and use it in GitHub Desktop.
print queries quantity in django
from django.db import connection
def print_queries_quantity(func):
def wrapper(self, *args, **kwargs):
old = len(connection.queries)
ret = func(self, *args, **kwargs)
quantity = len(connection.queries) - old
print '%d queries in %s' % (quantity, func.__name__)
return ret
return wrapper
#example
@print_queries_quantity
def get_object(self):
obj = None
# make queries
return obj
# output example
# 10 queries in get_object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment