Open
Description
I have a situation where I have three models that can be targets, and each one needs different optimizations.
An optimal prefetch looks like:
class MyActionManager(ActionManager):
def get_queryset(self):
prefetch_target = GenericPrefetch(
"target", [
Celebration.objects.select_related('type', 'user'),
Milestone.objects.select_related('type', 'user'),
Review.objects.select_related('author').prefetch_related('users', 'locations', 'teams')
]
)
prefetch_actor = GenericPrefetch(
"actor", [
User.objects.all(),
]
)
return MyActionQuerySet(self.model, using=self._db).prefetch_related(prefetch_actor).prefetch_related(prefetch_target)
If we add in fetch_generic_realtions before the prefetch it will break the generic prefetch behavior.
I think possibly the GFK QuerySet might be able to use GenericPrefetch?
Metadata
Metadata
Assignees
Labels
No labels