python Programming Glossary: connection.queries
Django: display time it took to load a page on every page http://stackoverflow.com/questions/17751163/django-display-time-it-took-to-load-a-page-on-every-page # get number of db queries before we do anything n len connection.queries # time the view start time response view_func request view_args.. the db time for the queries just run db_queries len connection.queries n if db_queries db_time reduce add float q 'time' for q in.. if db_queries db_time reduce add float q 'time' for q in connection.queries n else db_time 0.0 # and backout python time python_time total_time..
Django Query using .order_by() and .latest() http://stackoverflow.com/questions/3736964/django-query-using-order-by-and-latest django.db import connection MyModel.objects.latest print connection.queries 1 'sql' This prints SELECT app_mymodel . id app_mymodel . creation_date.. 2 MyModel.objects.order_by 'creation_date' .latest print connection.queries 1 'sql' prints SELECT app_mymodel . id app_mymodel . creation_date.. for objects.latest . MyModel.objects.latest 'id' print connection.queries 1 'sql' shows SELECT app_mymodel . id app_mymodel . creation_date..
log all sql queries http://stackoverflow.com/questions/4375784/log-all-sql-queries out where should I put from django.db import connection connection.queries to log everything to one file So my question is what should..
|