| | 951 | ``iterator()`` |
|---|
| | 952 | ~~~~~~~~~~~~ |
|---|
| | 953 | |
|---|
| | 954 | Evaluates the ``QuerySet`` (by performing the query) and returns an |
|---|
| | 955 | `iterator`_ over the results. A ``QuerySet`` typically reads all of |
|---|
| | 956 | its results and instantiates all of the corresponding objects the |
|---|
| | 957 | first time you access it; ``iterator()`` will instead read results and |
|---|
| | 958 | instantiate objects in discrete chunks, yielding them one at a |
|---|
| | 959 | time. For a ``QuerySet`` which returns a large number of objects, this |
|---|
| | 960 | often results in better performance and a significant reduction in |
|---|
| | 961 | memory use. |
|---|
| | 962 | |
|---|
| | 963 | Note that using ``iterator()`` on a ``QuerySet`` which has already |
|---|
| | 964 | been evaluated will force it to evaluate again, repeating the query. |
|---|
| | 965 | |
|---|
| | 966 | .. _iterator: http://www.python.org/dev/peps/pep-0234/ |
|---|
| | 967 | |
|---|