Try to place it in your views, but be sure your querysets are evaluated.
But I would recommend you to use django-silk, it's much more powerful kit for your goal.
I know how to do it in db shell, but I need to do it in the code in which file and where should I place print(len(connection)). Maybe I need to do something else?
Can't count PostgeSQL requests in django