diff options
| author | Alex Morozov <inductor2000@mail.ru> | 2015-11-02 15:42:43 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-03 12:24:45 +0000 |
| commit | ecb3e314cb0ce4b7fe65e208ea76557443ae6e06 (patch) | |
| tree | 98a72fd2a8068ff3ab3cebd69cade0af46100244 /docs | |
| parent | a3bbc38d545390f605f9bed947c9fdfe2ffa6055 (diff) | |
[1.9.x] Fixed #25132 -- Documented how to retrieve a single value using values_list() and get().
Backport of 4373eac99828d99718a7b245d160e7e64fce2e95 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/querysets.txt | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 25fa01421d..458c70d736 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -641,6 +641,12 @@ It is an error to pass in ``flat`` when there is more than one field. 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. +A common need is to get a specific field value of a certain model instance. To +achieve that, use ``values_list()`` followed by a ``get()`` call:: + + >>> Entry.objects.values_list('headline', flat=True).get(pk=1) + 'First entry' + dates ~~~~~ |
