Search code examples
djangodjango-debug-toolbar

In django_debug_toolbar how can I see the queries on submit


I'm doing some extra queries(using object attributes) on submit/save(to define the file upload_to) and I want to see them in the django_debug_toolbar.

I'm doing the same queries for each file, and I want to do some optimization, to see how many there are, is just one call, or are called for each attribute.


Solution

  • Use the debug_toolbar.panels.sql.SQLPanel. In your settings file:

    DEBUG_TOOLBAR_PANELS = [
        'debug_toolbar.panels.versions.VersionsPanel',
        'debug_toolbar.panels.timer.TimerPanel',
        'debug_toolbar.panels.settings.SettingsPanel',
        'debug_toolbar.panels.headers.HeadersPanel',
        'debug_toolbar.panels.request.RequestPanel',
        'debug_toolbar.panels.sql.SQLPanel',  # important one
        'debug_toolbar.panels.staticfiles.StaticFilesPanel',
        'debug_toolbar.panels.templates.TemplatesPanel',
        'debug_toolbar.panels.cache.CachePanel',
        'debug_toolbar.panels.signals.SignalsPanel',
        'debug_toolbar.panels.logging.LoggingPanel',
        'debug_toolbar.panels.redirects.RedirectsPanel',
    ]
    

    After that, when you POST to your URL and display some HTML as result you should see a section in the debug toolbar to see which queries were executed. You might need to temporally disable any redirections in order to get the profiling for the POST and not for the redirected GET.