bgneal@1: from django.db import connection bgneal@1: from django.template import Template, Context bgneal@1: bgneal@1: class SQLLogMiddleware: bgneal@1: bgneal@1: def process_response ( self, request, response ): bgneal@1: time = 0.0 bgneal@1: for q in connection.queries: bgneal@1: time += float(q['time']) bgneal@1: t = Template(''' bgneal@1:

Total query count: {{ count }}
bgneal@1: Total execution time: {{ time }}

bgneal@1:
    bgneal@1: {% for sql in sqllog %} bgneal@1:
  1. {{ sql.time }}: {{ sql.sql }}
  2. bgneal@1: {% endfor %} bgneal@1:
bgneal@1: ''') bgneal@1: response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))) bgneal@1: return response