How to pretty print SQL from Django

from blog Roman Imankulov, | ↗ original
Often, I find myself experimenting in the Django console with ad-hoc model queries. Where it’s not clear how Django turns a queryset to SQL, I find it helpful to print the resulting query. Django QuerySet object has a query attribute. However, its format would benefit from extra formatting. I used pygments and sqlparse to make the output of query...