M
M
maksam072021-05-06 20:39:08
Django
maksam07, 2021-05-06 20:39:08

How to get raw DB query when we get data by Model.objects....?

Good evening. The question has ripened that I want to look under the hood of some functions. Now I want to know which django generates a query to the database when we select data, filter, sort, merge, etc. Is it possible to display this information somehow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2021-05-06
@maksam07

If a QuerySet is returned (and not an object, as in the case of .first or .get), then QS has a .query attribute
str(Model.objects.filter(...).values_list(...).query)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question