Created
October 23, 2015 23:32
-
-
Save iver56/796ad44194278790eea5 to your computer and use it in GitHub Desktop.
Dump the sql that django generates
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
import sqlparse | |
from django.db import connection | |
from django.core.signals import request_finished | |
def finished(sender, **kwargs): | |
for query in connection.queries: | |
print "\n" + "(" + query['time'] + " s) " + sqlparse.format(query['sql'], reindent=True, keyword_case="upper") + "\n" | |
if len(connection.queries) > 0: | |
print "NUMBER OF DB QUERIES FOR THIS REQUEST:", len(connection.queries) | |
request_finished.connect(finished) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment