What is the difference between values() and values_list() in a QuerySet?
Last updated
Both return lightweight data instead of model instances: values() yields dictionaries keyed by field name, while values_list() yields tuples of field values.
values(): dicts: Each row is{'field': value, ...}; convenient for JSON-like output.values_list(): tuples:Each row is a tuple of values in field order.
Pass
flat=Truewith a single field to get a flat list of scalars.
Why use them: Skip model instantiation overhead when you only need raw columns.
[lang:python]
Book.objects.values("id", "title") # [{'id': 1, 'title': 'X'}]
Book.objects.values_list("id", "title") # [(1, 'X')]
Book.objects.values_list("title", flat=True) # ['X', 'Y']