from django.db import connection
models = Models.objects.filter(ativo=True)
sql, params = models.query.sql_with_params()
with connection.cursor() as cursor:
print(cursor.mogrify(sql, params).decode("utf-8"))
from django.db import connection
models = Models.objects.filter(ativo=True)
for query in connection.queries:
print(query['sql'])