diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-08-04 15:28:39 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-09-06 15:32:32 -0400 |
| commit | f3c956214366d590c0a588aaad83f8f770c78b76 (patch) | |
| tree | 2c335a533c3c2fdd8ef2fe1573574dfc4728b01e /docs/ref/models | |
| parent | a027447f5606d60358e5da76c0e8233732ad2b17 (diff) | |
Fixed #15648 -- Allowed QuerySet.values_list() to return a namedtuple.
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/querysets.txt | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 5973f2b5a3..6d66b05957 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -626,7 +626,7 @@ You can also refer to fields on related models with reverse relations through ``values_list()`` ~~~~~~~~~~~~~~~~~ -.. method:: values_list(*fields, flat=False) +.. method:: values_list(*fields, flat=False, named=False) This is similar to ``values()`` except that instead of returning dictionaries, it returns tuples when iterated over. Each tuple contains the value from the @@ -651,6 +651,15 @@ rather than one-tuples. An example should make the difference clearer:: It is an error to pass in ``flat`` when there is more than one field. +You can pass ``named=True`` to get results as a +:func:`~python:collections.namedtuple`:: + + >>> Entry.objects.values_list('id', 'headline', named=True) + <QuerySet [Row(id=1, headline='First entry'), ...]> + +Using a named tuple may make use of the results more readable, at the expense +of a small performance penalty for transforming the results into a named tuple. + If you don't pass any values to ``values_list()``, it will return all the fields in the model, in the order they were declared. @@ -688,6 +697,10 @@ not having any author:: Support for expressions in ``*fields`` was added. +.. versionchanged:: 2.0 + + The ``named`` parameter was added. + ``dates()`` ~~~~~~~~~~~ |
