(Django1.11.11)
>>> from django.db import connection >>> connection.queries >>> from foo.models import Bar >>> bars = Bar.objects.filter(name='foobar') >>> connection.queries[-1]['sql'] "SELECT `foo_bar`.`id`, `foo_bar`.`name`, `foo_bar`.`updated_at` FROM `foo_bar` WHERE `foo_bar`.`name` = 'foobar' LIMIT 21"