Search code examples
pythonsqldjangodjango-modelsreset

Is there any way to clear django.db.connection.queries?


I want to monitor query time in my system(built with Django models).

Finally, I found django.db.connection.queries.

It shows all queries and time taking for it.

Using this, I want to print the list of which I have done queries at regular interval and then I want to clear the list I printed after printing.

It seems to have methods for a list object(pop, remove and so on).

But Even though I call pop(), It doesn't have any effect, still showing the same length.

How can I clear the list..?

Or Is there any other methods for my intention?

p.s I also found Django-debug-toolbar but it seems only for view part.


Solution

  • You can call reset_queries() from the django.db module.

    from django.db import reset_queries
    reset_queries()