Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does django's values() values_list() get evaluated?

Django docs specify when queryset gets evaluated.

When does ValuesListQuerySet, ValuesQuerySet evaluated? (when does it hit the DB?)

like image 982
eugene Avatar asked Oct 08 '14 10:10

eugene


People also ask

What is values and Values_list in Django?

Django values_list() is an optimization to grab specific data from the database instead of building and loading the entire model instance.

Why are QuerySets considered lazy?

This is because a Django QuerySet is a lazy object. It contains all of the information it needs to populate itself from the database, but will not actually do so until the information is needed.


1 Answers

It acts the same as any normal QuerySet, just its output is transformed directly from model instances to dictionaries/tuples respectively before being passed on to you, as per https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.values

like image 116
Martin B. Avatar answered Nov 09 '22 13:11

Martin B.