Fixed #16937 - added QuerySet.prefetch_related to prefetch many related objects.

Many thanks to akaariai for lots of review and feedback, bug finding,
additional unit tests and performance testing.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16930 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2011-10-05 23:14:52 +00:00
parent d30fbf8b78
commit 662eea116f
10 changed files with 968 additions and 24 deletions

View file

@ -141,10 +141,12 @@ retrieving it all in one query. This is particularly important if you have a
query that is executed in a loop, and could therefore end up doing many database
queries, when only one was needed. So:
Use ``QuerySet.select_related()``
---------------------------------
Use ``QuerySet.select_related()`` and ``prefetch_related()``
------------------------------------------------------------
Understand :ref:`QuerySet.select_related() <select-related>` thoroughly, and use it:
Understand :meth:`~django.db.models.query.QuerySet.select_related` and
:meth:`~django.db.models.query.QuerySet.prefetch_related` thoroughly, and use
them:
* in view code,