Created
August 1, 2013 07:28
-
-
Save julen/6129184 to your computer and use it in GitHub Desktop.
Printing human-readable SQL queries to the console in scenarios where the django-debug-toolbar isn't available.
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 | |
qs = MyObject.objects.filter(foo='bar', baz__startswith='baz') | |
sql, params = qs.query.sql_with_params() | |
print sqlparse.format(str(sql % params), | |
reindent=True, keyword_case='upper') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment