[4.2.x] Fixed #30355 -- Doc'd interaction between custom managers and prefetch_related().
Backport of 5f2308710b5a3d9f5f135b7ade08214f5c154ec4 from main
This commit is contained in:
parent
b2355a8df3
commit
eb84c068ed
@ -1802,6 +1802,18 @@ methods::
|
|||||||
|
|
||||||
b.entry_set(manager="entries").is_published()
|
b.entry_set(manager="entries").is_published()
|
||||||
|
|
||||||
|
.. admonition:: Interaction with prefetching
|
||||||
|
|
||||||
|
When calling :meth:`~django.db.models.query.QuerySet.prefetch_related` with
|
||||||
|
a reverse relation, the default manager will be used. If you want to
|
||||||
|
prefetch related objects using a custom reverse manager, use
|
||||||
|
:class:`Prefetch() <django.db.models.Prefetch>`. For example::
|
||||||
|
|
||||||
|
from django.db.models import Prefetch
|
||||||
|
|
||||||
|
prefetch_manager = Prefetch("entry_set", queryset=Entry.entries.all())
|
||||||
|
Blog.objects.prefetch_related(prefetch_manager)
|
||||||
|
|
||||||
Additional methods to handle related objects
|
Additional methods to handle related objects
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user