Created
May 22, 2014 03:25
-
-
Save erickgnavar/fe9a1805b87365f25252 to your computer and use it in GitHub Desktop.
print queries quantity in django
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
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