Skip to content

Instantly share code, notes, and snippets.

@RodrigoCMoraes
Last active March 22, 2020 02:02
Show Gist options
  • Save RodrigoCMoraes/a51df8ba26ac44d4fa76ca4619ecd882 to your computer and use it in GitHub Desktop.
Save RodrigoCMoraes/a51df8ba26ac44d4fa76ca4619ecd882 to your computer and use it in GitHub Desktop.
Function to get the amount of queries of django query
def amount_queries():
"""Usage:
start_num_queries = amount_queries()
... plent of code with django orm queries
end_num_queries = amount_queries()
num_queries = end_num_queries - start_num_queries
"""
from django.db import connection
from django.conf import settings
settings.DEBUG = True # side effect
num_queries = len(connection.queries)
return num_queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment