2π
β
In both situations, you are not triggering the queryset to be evaluated. filter
does nothing but composing sql statement in the underline implementation, so you never hit the database in either of the cases, you were just composing several sql statement that sits in your program. Only when you start using the variables then django starts to do the queryset evaluation.
Django doc about querysets are lazy. If every orm statement is hitting the databsase itβs not going to be optimal.
π€Shang Wang
Source:stackexchange.com