Part of my django admin site that uses a lot of Inlines is running slowly and based on this question I think that it might have to do with the number of SQL queries it generates. I'd like to count the number of SQL queries so I can test some changes. I know how to do this on a custom-written view but I can't figure out how to do it for a standard admin view.
Here's how I would test my own view. The view is called weight_plot
and the app is called runner
.
from django.test.client import RequestFactory
from django.conf import settings
settings.DEBUG = True
from django.db import connection
import runner.views
myview = runner.views.weight_plot
request = factory.get('/weights')
response = myview(request)
n_queries = len(connection.queries)
This works, and now I'd like to see how many queries are needed to load the page at https://example.com/admin/runner/MODEL_NAME/add/
. But I can't figure out what view to use for this instead of myview
above.