segunda-feira, 1 de junho de 2009

Como exibir as queries SQL executadas no Django

>manage.py shell
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Entry
>>> ds = Entry.objects.dates('pub_date', 'month')
>>> ds
[datetime.datetime(2008, 12, 1, 0, 0)]
>>> from django.db import connection
>>> connection.queries[-1]
{'time': '0.000', 'sql': u'SELECT DISTINCT django_date_trunc("month",
"blog_entry"."pub_date") FROM "blog_entry" ORDER BY 1 ASC LIMIT 21'}

Nenhum comentário: