Troubleshooting Django

To see what SQL the command is executing:

from django.db import connection
MODEL.objects.latest()
connection.queries

This shows what latest is doing in SQL

When you get a query back, then you can look at it with sql_with_params

MODEL.objects.filter(created_by__username="fred").query.sql_with_params()

The Django Debug Toolbar is useful to look at the SQL queries and how many times things are duplicated.

 

Leave a comment