Loading docs/faq/models.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ FAQ: Databases and models ========================= .. _faq-see-raw-sql-queries: How can I see the raw SQL queries Django is running? ---------------------------------------------------- Loading docs/index.txt +2 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,8 @@ The model layer * **Other:** :ref:`Supported databases <ref-databases>` | :ref:`Legacy databases <howto-legacy-databases>` | :ref:`Providing initial data <howto-initial-data>` :ref:`Providing initial data <howto-initial-data>` | :ref:`Optimize database access <topics-db-optimization>` The template layer ================== Loading docs/ref/models/querysets.txt +24 −9 Original line number Diff line number Diff line Loading @@ -66,6 +66,18 @@ You can evaluate a ``QuerySet`` in the following ways: iterating over a ``QuerySet`` will take advantage of your database to load data and instantiate objects only as you need them. * **bool().** Testing a ``QuerySet`` in a boolean context, such as using ``bool()``, ``or``, ``and`` or an ``if`` statement, will cause the query to be executed. If there is at least one result, the ``QuerySet`` is ``True``, otherwise ``False``. For example:: if Entry.objects.filter(headline="Test"): print "There is at least one Entry with the headline Test" Note: *Don't* use this if all you want to do is determine if at least one result exists, and don't need the actual objects. It's more efficient to use ``exists()`` (see below). .. _pickling QuerySets: Pickling QuerySets Loading Loading @@ -302,7 +314,7 @@ a model which defines a default ordering, or when using ordering was undefined prior to calling ``reverse()``, and will remain undefined afterward). .. _querysets-distinct: .. _queryset-distinct: ``distinct()`` ~~~~~~~~~~~~~~ Loading Loading @@ -336,6 +348,8 @@ query spans multiple tables, it's possible to get duplicate results when a ``values()`` call. .. _queryset-values: ``values(*fields)`` ~~~~~~~~~~~~~~~~~~~ Loading Loading @@ -616,7 +630,7 @@ call, since they are conflicting options. Both the ``depth`` argument and the ability to specify field names in the call to ``select_related()`` are new in Django version 1.0. .. _extra: .. _queryset-extra: ``extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loading Loading @@ -1062,17 +1076,18 @@ Example:: If you pass ``in_bulk()`` an empty list, you'll get an empty dictionary. .. _queryset-iterator: ``iterator()`` ~~~~~~~~~~~~~~ Evaluates the ``QuerySet`` (by performing the query) and returns an `iterator`_ over the results. A ``QuerySet`` typically reads all of its results and instantiates all of the corresponding objects the first time you access it; ``iterator()`` will instead read results and instantiate objects in discrete chunks, yielding them one at a time. For a ``QuerySet`` which returns a large number of objects, this often results in better performance and a significant reduction in memory use. `iterator`_ over the results. A ``QuerySet`` typically caches its results internally so that repeated evaluations do not result in additional queries; ``iterator()`` will instead read results directly, without doing any caching at the ``QuerySet`` level. For a ``QuerySet`` which returns a large number of objects, this often results in better performance and a significant reduction in memory Note that using ``iterator()`` on a ``QuerySet`` which has already been evaluated will force it to evaluate again, repeating the query. Loading docs/topics/db/aggregation.txt +1 −1 Original line number Diff line number Diff line Loading @@ -353,7 +353,7 @@ without any harmful effects, since that is already playing a role in the query. This behavior is the same as that noted in the queryset documentation for :ref:`distinct() <querysets-distinct>` and the general rule is the same: :ref:`distinct() <queryset-distinct>` and the general rule is the same: normally you won't want extra columns playing a part in the result, so clear out the ordering, or at least make sure it's restricted only to those fields you also select in a ``values()`` call. Loading docs/topics/db/index.txt +1 −0 Original line number Diff line number Diff line Loading @@ -17,3 +17,4 @@ model maps to a single database table. sql transactions multi-db optimization Loading
docs/faq/models.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ FAQ: Databases and models ========================= .. _faq-see-raw-sql-queries: How can I see the raw SQL queries Django is running? ---------------------------------------------------- Loading
docs/index.txt +2 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,8 @@ The model layer * **Other:** :ref:`Supported databases <ref-databases>` | :ref:`Legacy databases <howto-legacy-databases>` | :ref:`Providing initial data <howto-initial-data>` :ref:`Providing initial data <howto-initial-data>` | :ref:`Optimize database access <topics-db-optimization>` The template layer ================== Loading
docs/ref/models/querysets.txt +24 −9 Original line number Diff line number Diff line Loading @@ -66,6 +66,18 @@ You can evaluate a ``QuerySet`` in the following ways: iterating over a ``QuerySet`` will take advantage of your database to load data and instantiate objects only as you need them. * **bool().** Testing a ``QuerySet`` in a boolean context, such as using ``bool()``, ``or``, ``and`` or an ``if`` statement, will cause the query to be executed. If there is at least one result, the ``QuerySet`` is ``True``, otherwise ``False``. For example:: if Entry.objects.filter(headline="Test"): print "There is at least one Entry with the headline Test" Note: *Don't* use this if all you want to do is determine if at least one result exists, and don't need the actual objects. It's more efficient to use ``exists()`` (see below). .. _pickling QuerySets: Pickling QuerySets Loading Loading @@ -302,7 +314,7 @@ a model which defines a default ordering, or when using ordering was undefined prior to calling ``reverse()``, and will remain undefined afterward). .. _querysets-distinct: .. _queryset-distinct: ``distinct()`` ~~~~~~~~~~~~~~ Loading Loading @@ -336,6 +348,8 @@ query spans multiple tables, it's possible to get duplicate results when a ``values()`` call. .. _queryset-values: ``values(*fields)`` ~~~~~~~~~~~~~~~~~~~ Loading Loading @@ -616,7 +630,7 @@ call, since they are conflicting options. Both the ``depth`` argument and the ability to specify field names in the call to ``select_related()`` are new in Django version 1.0. .. _extra: .. _queryset-extra: ``extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loading Loading @@ -1062,17 +1076,18 @@ Example:: If you pass ``in_bulk()`` an empty list, you'll get an empty dictionary. .. _queryset-iterator: ``iterator()`` ~~~~~~~~~~~~~~ Evaluates the ``QuerySet`` (by performing the query) and returns an `iterator`_ over the results. A ``QuerySet`` typically reads all of its results and instantiates all of the corresponding objects the first time you access it; ``iterator()`` will instead read results and instantiate objects in discrete chunks, yielding them one at a time. For a ``QuerySet`` which returns a large number of objects, this often results in better performance and a significant reduction in memory use. `iterator`_ over the results. A ``QuerySet`` typically caches its results internally so that repeated evaluations do not result in additional queries; ``iterator()`` will instead read results directly, without doing any caching at the ``QuerySet`` level. For a ``QuerySet`` which returns a large number of objects, this often results in better performance and a significant reduction in memory Note that using ``iterator()`` on a ``QuerySet`` which has already been evaluated will force it to evaluate again, repeating the query. Loading
docs/topics/db/aggregation.txt +1 −1 Original line number Diff line number Diff line Loading @@ -353,7 +353,7 @@ without any harmful effects, since that is already playing a role in the query. This behavior is the same as that noted in the queryset documentation for :ref:`distinct() <querysets-distinct>` and the general rule is the same: :ref:`distinct() <queryset-distinct>` and the general rule is the same: normally you won't want extra columns playing a part in the result, so clear out the ordering, or at least make sure it's restricted only to those fields you also select in a ``values()`` call. Loading
docs/topics/db/index.txt +1 −0 Original line number Diff line number Diff line Loading @@ -17,3 +17,4 @@ model maps to a single database table. sql transactions multi-db optimization