Skip to content

Conversation

@ljodal
Copy link
Contributor

@ljodal ljodal commented Jul 3, 2022

This adds support for calling <Manager>.from_queryset(<QuerySet>)() inline in models, for example like this:

class MyModel(models.Model):
    objects = MyManager.from_queryset(MyQuerySet)()

This is done by inspecting the class body in the transform_class_hook

There's a few broken tests I haven't figured out yet, but this mostly appears to be working just fine.

Related issues

This adds support for calling <Manager>.from_queryset(<QuerySet>)()
inline in models, for example like this:

    class MyModel(models.Model):
        objects = MyManager.from_queryset(MyQuerySet)()

This is done by inspecting the class body in the transform_class_hook
@ljodal ljodal changed the title Add support for inline from_queryset in model classes Add support for inline from_queryset in model classes Jul 3, 2022
@ljodal ljodal force-pushed the add-support-for-inline-from-queryset branch from a0d8d6d to b269fcc Compare July 3, 2022 20:57
When the manager is added at the class level, which happened when it was
created inline in the model body, it's not possible to retrieve the
manager again based on fullname. That lead to problems with inheritance
and the default manager.
@ljodal ljodal force-pushed the add-support-for-inline-from-queryset branch from b269fcc to 5444f45 Compare July 3, 2022 20:59
@ljodal ljodal marked this pull request as ready for review July 3, 2022 21:10
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.

Looks great! Awesome work!

@sobolevn sobolevn merged commit 830d74b into typeddjango:master Jul 13, 2022
@ljodal ljodal deleted the add-support-for-inline-from-queryset branch July 13, 2022 07:25
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