[Answer]-How will I get the time taken by a django orm query?

1👍

One option is to use django-debug-toolbar: it measures every query done on every view.

It is a must on any django app.

Regarding the other questions:

  1. I would say they are equivalent. In Django code, get uses filter and retrieves the first element.

  2. should also be equivalent because filter and exclude are just different names for filter(Q(...)) and filter(~Q()) and chaining is equivalent to have a comma: the queries are connected with by AND.
    However, because in one you are using "open" and in the other "close", this can have an impact in how the particular backend will perform, and AFAIK this difference can only be measured by profiling.

Leave a comment