# These are some commands to copy and paste into a manage.py shell session
# in order to find out what SQL queries are generated by a view

## turn on DEBUG so that ``connection.queries`` gets populated
from django.conf import settings
settings.DEBUG = True
from django.db import connection


## handy function for printing the queries
def print_q(queries, sort=None, truncate=100):
    if sort is not None:
        queries = sorted(queries, key=lambda x: float(x['time']), reverse=not sort)
    for q in queries:
        print q['time'], q['sql'][:truncate]

print_q(connection.queries, True)


## call the view!
from django.test.client import Client
c = Client()

url = '/my/url'
c.get(url)


print_q(connection.queries, True)
sum(map(lambda x: float(x['time']), connection.queries))