Use the --debug-sql option of the Django test runner.
--debug-sql
Enables SQL logging for failing tests. If --verbosity is 2, then queries in passing tests are also output.
./manage.py test --debug-sql