Code

Ticket #5275: 5275.diff

File 5275.diff, 1.0 KB (added by ubernostrum, 7 years ago)

Patch documenting QuerySet.iterator()

Line 
1Index: docs/db-api.txt
2===================================================================
3--- docs/db-api.txt     (revision 6248)
4+++ docs/db-api.txt     (working copy)
5@@ -948,6 +948,23 @@
6 
7 If you pass ``in_bulk()`` an empty list, you'll get an empty dictionary.
8 
9+``iterator()``
10+~~~~~~~~~~~~
11+
12+Evaluates the ``QuerySet`` (by performing the query) and returns an
13+`iterator`_ over the results. A ``QuerySet`` typically reads all of
14+its results and instantiates all of the corresponding objects the
15+first time you access it; ``iterator()`` will instead read results and
16+instantiate objects in discrete chunks, yielding them one at a
17+time. For a ``QuerySet`` which returns a large number of objects, this
18+often results in better performance and a significant reduction in
19+memory use.
20+
21+Note that using ``iterator()`` on a ``QuerySet`` which has already
22+been evaluated will force it to evaluate again, repeating the query.
23+
24+.. _iterator: http://www.python.org/dev/peps/pep-0234/
25+
26 ``latest(field_name=None)``
27 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
28