#33651: Support prefetch GenericForeignKey with custom queryset.
-------------------------------------+-------------------------------------
Reporter: elonzh | Owner:
| Gullapalli Saisurya Revanth
Type: New feature | Status: assigned
Component: | Version: 4.0
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: GenericForeignKey | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Todor Velichkov):
Hi everyone, I took a brief look at the conversation in the pull request
[https://github.com/django/django/pull/15636 #15636] and I have a
question about the issue being discussed there (passing list of querysets
into an queryset argument).
Is there anything specific about this, that is enforcing the use of a list
of querysets? Is it possible to send as many `GenericPrefetch` objects as
the number of querysets being required ? For example:
{{{
Node.objects.prefetch_related(
GenericPrefetch("content_object", queryset=ItemA.objects.all()),
GenericPrefetch("content_object", queryset=ItemB.objects.all()),
)
}}}
this is in the spirit of the current `Prefetch` class, which actually
allows you to prefetch multiple levels of objects, splitted into different
prefetch calls. i.e:
{{{
Book.objects.prefetch_related(
Prefetch("author", queryset=Author.objects.all()),
Prefetch("author__house", queryset=House.objects.all()),
)
}}}
And now I'm a little bit repeating myself with ticket [ticket:24272], but
this could probably open the door for reusing `related_query_name` when
there is a defined `GenericRelation` which could give us the following
interface w/o using the generic `content_object` argument:
{{{
TaggedItem.objects.all().prefetch_related(
GenericPrefetch('books',
queryset=Book.objects.all().select_related('author')),
GenericPrefetch('movies',
queryset=Movie.objects.all().select_related('director')),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33651#comment:19>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070184a3d59c3a-c9910f24-45b6-45e2-86e6-9e86f7d8d483-000000%40eu-central-1.amazonses.com.