浏览代码

Fixed #25132 -- Documented how to retrieve a single value using values_list() and get().

Alex Morozov 9 年之前
父节点
当前提交
4373eac998
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      docs/ref/models/querysets.txt

+ 6 - 0
docs/ref/models/querysets.txt

@@ -625,6 +625,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
 ~~~~~