Skip to content

Conversation

@UnknownPlatypus
Copy link
Contributor

I have made things!

Expand #2786 to support cases where the Prefetch objects are passed using a star arg.
I had something very similar to this at work:

def _get_prefetches() -> tuple[
    Prefetch[QuerySet[Tag], Literal["every_tags"]],
    Prefetch[QuerySet[Tag], Literal["every_tags2"]],
]:
    return (
        Prefetch("tags", Tag.objects.all(), to_attr="every_tags"),
        Prefetch("tags", Tag.objects.all(), to_attr="every_tags"),
    )

##
my_model = (
    MyModel.objects
    .prefetch_related(*_get_prefetches(agent_main_group))
    .get()
)

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sobolevn sobolevn merged commit caf25d9 into typeddjango:master Sep 1, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants