Skip to content

Latest commit

 

History

History
27 lines (25 loc) · 528 Bytes

printar_query_sql_django.md

File metadata and controls

27 lines (25 loc) · 528 Bytes

Para printar uma query string completa

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"))

Para ver as querys que foram executadas

from django.db import connection
models = Models.objects.filter(ativo=True)
for query in connection.queries:
    print(query['sql'])