Django query time using the connection module

Dec 21, 2016

The Django connection module keeps track of recent queries. To see the SQL code and time taken to run the queries, have a look at the connection.queries field.

from django.db import connection
from models import MyModel

stuffs = MyModel.objects.filter(field_1=1, field_2='2')

print(connection.queries)

This works only in debug mode, i.e. you need to set DEBUG = True in your Django settings file.