From cac94dd8aa2fb49cd2e06b5b37cf039257284bb0 Mon Sep 17 00:00:00 2001 From: Clément Escolano Date: Tue, 1 Aug 2023 23:31:40 +0200 Subject: Fixed #33651 -- Added support for prefetching GenericForeignKey. Co-authored-by: revanthgss Co-authored-by: Mariusz Felisiak --- docs/ref/models/querysets.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'docs/ref/models') diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 9d90f4b19e..cd6c13fc05 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1154,10 +1154,15 @@ many-to-many, many-to-one, and cannot be done using ``select_related``, in addition to the foreign key and one-to-one relationships that are supported by ``select_related``. It also supports prefetching of -:class:`~django.contrib.contenttypes.fields.GenericForeignKey`, however, it -must be restricted to a homogeneous set of results. For example, prefetching -objects referenced by a ``GenericForeignKey`` is only supported if the query -is restricted to one ``ContentType``. +:class:`~django.contrib.contenttypes.fields.GenericForeignKey`, however, the +queryset for each ``ContentType`` must be provided in the ``querysets`` +parameter of :class:`~django.contrib.contenttypes.prefetch.GenericPrefetch`. + +.. versionchanged:: 5.0 + + Support for prefetching + :class:`~django.contrib.contenttypes.fields.GenericForeignKey` with + non-homogeneous set of results was added. For example, suppose you have these models:: -- cgit v1.3