summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-08-04 15:28:39 +0500
committerTim Graham <timograham@gmail.com>2017-09-06 15:32:32 -0400
commitf3c956214366d590c0a588aaad83f8f770c78b76 (patch)
tree2c335a533c3c2fdd8ef2fe1573574dfc4728b01e /docs
parenta027447f5606d60358e5da76c0e8233732ad2b17 (diff)
Fixed #15648 -- Allowed QuerySet.values_list() to return a namedtuple.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/querysets.txt15
-rw-r--r--docs/releases/2.0.txt3
2 files changed, 17 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()``
~~~~~~~~~~~
diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt
index c8ec169e3c..7b2df87fcf 100644
--- a/docs/releases/2.0.txt
+++ b/docs/releases/2.0.txt
@@ -291,6 +291,9 @@ Models
* Added support for expressions in :attr:`Meta.ordering
<django.db.models.Options.ordering>`.
+* The new ``named`` parameter of :meth:`.QuerySet.values_list` allows fetching
+ results as named tuples.
+
Pagination
~~~~~~~~~~