[Django]-Why no append() method on Django ValuesListQuerySet?

4👍

From my comment:

django querysets are not lists…….though they still support some list operations

Also as programmersbook commented…..django querysets are lazy i.e. The queries are executed when the queryset is first accessed. Let us say you have chained a long filters for getting a queryset, even then the database will be hit only once, at the time of access of queryset value.
Now let us say you have a queryset:

sample_set = SampleModel.objects.filter(sample_field='sample_value').filter(another_sample_field='another_sample_value') 

The queryset returned will have a corresponding single sql query like

SELECT something FROM sometable 
WHERE sample_field='sample_value' 
AND another_sample_field='another_sample_value'

There is no way that one can achieve something like sample_set.append(sample_object) as sample_set represents an SQL statement.

Leave a comment