One of the benefits of
One of the ways that executes the query is using iteration:
In the below ways your query will be evaluated (executed):
- repr
- len
- list (e.g.: `list(Entry.objects.all())`)
- bool
#python #django #querySet #query_set #evaluation
Django`'s `QuerySet
is that you can apply filters on it, slice it and move it around your classes without actually hitting the database until you do so.One of the ways that executes the query is using iteration:
for c in Course.objects.all():
print(c.title)
NOTE:
the first time you iterate over the query, it hits the database and get the result NOT in each iteration.In the below ways your query will be evaluated (executed):
- repr
- len
- list (e.g.: `list(Entry.objects.all())`)
- bool
#python #django #querySet #query_set #evaluation