mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #17001 -- Custom querysets for prefetch_related.
This patch introduces the Prefetch object which allows customizing prefetch operations. This enables things like filtering prefetched relations, calling select_related from a prefetched relation, or prefetching the same relation multiple times with different querysets. When a Prefetch instance specifies a to_attr argument, the result is stored in a list rather than a QuerySet. This has the fortunate consequence of being significantly faster. The preformance improvement is due to the fact that we save the costly creation of a QuerySet instance. Thanks @akaariai for the original patch and @bmispelon and @timgraham for the reviews.
This commit is contained in:
committed by
Anssi Kääriäinen
parent
b1b04df065
commit
f51c1f5900
@@ -98,6 +98,21 @@ Using a custom manager when traversing reverse relations
|
||||
It is now possible to :ref:`specify a custom manager
|
||||
<using-custom-reverse-manager>` when traversing a reverse relationship.
|
||||
|
||||
New ``Prefetch`` object for advanced ``prefetch_related`` operations.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The new :class:`~django.db.models.Prefetch` object allows customizing
|
||||
prefetch operations.
|
||||
|
||||
You can specify the ``QuerySet`` used to traverse a given relation
|
||||
or customize the storage location of prefetch results.
|
||||
|
||||
This enables things like filtering prefetched relations, calling
|
||||
:meth:`~django.db.models.query.QuerySet.select_related()` from a prefetched
|
||||
relation, or prefetching the same relation multiple times with different
|
||||
querysets. See :meth:`~django.db.models.query.QuerySet.prefetch_related()`
|
||||
for more details.
|
||||
|
||||
Admin shortcuts support time zones
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user