aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql.py
blob: 2cc981b4a1ab638d6940452e95301ee81775b173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from debug_toolbar.panels import DebugPanel
from django.db import connection
from django.template import Context, Template

class SQLDebugPanel(DebugPanel):
    """
    Panel that displays information about the SQL queries run while processing the request.
    """
    name = 'SQL'
    
    def title(self):
        return '%d SQL Queries' % (len(connection.queries))

    def url(self):
        return ''

    def content(self):
        t = Template('''
            <dl>
                {% for q in queries %}
                    <dt><strong>{{ q.time }}</strong></dt>
                    <dd>{{ q.sql }}</dd>
                {% endfor %}
            </dl>
        ''')
        c = Context({'queries': connection.queries})
        return t.render(c)