N
N
neulwert2019-11-23 18:18:12
PostgreSQL
neulwert, 2019-11-23 18:18:12

When are QuerySet queries executed?

Please explain this short topic:

When QuerySet queries are executed
We can add as many filters as we want to the query object, but the actual
execution of the SQL query will occur when the
QuerySet is evaluated. QuerySet is only executed in these cases:
  • first iteration over the QuerySet collection;
  • when serializing or caching;
  • when calling the repr() or len() methods;
  • when we explicitly call the list() function, passing it as the QuerySet argument;
  • when using QuerySet in boolean expressions like bool(),

or, and, if.

The request object, as I understand it, can be called objects.get (). It's not clear to me what SQL queries are (is it the same as the query object in this paragraph?) and what the author means by calculating a QuerySet and iterating over a QuerySet collection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-11-23
@neulwert

this is for you

SQL queries
surprisingly, not in the know, but, just in case, this is a regular SQL query
, and what you are asking about is called ORM
ORM has many advantages and only two drawbacks:
1) ORM is 20-500% slower than RAW SQL
2) ORM leads to degradation
to the inability to write correct SQL
about correct SQL mutually - ORM can translate a query better than if it were written by a beginner, but only in a few cases
more practice - and you will see everything yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question