Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with as_manager? #293

Closed
tony opened this issue Dec 4, 2017 · 1 comment
Closed

Usage with as_manager? #293

tony opened this issue Dec 4, 2017 · 1 comment
Labels

Comments

@tony
Copy link
Member

tony commented Dec 4, 2017

In the changelog I see:

https://github.com/jazzband/django-model-utils/blob/master/CHANGES.rst#24-20151203

Remove PassThroughManager. Use Django's built-in QuerySet.as_manager() and/or Manager.from_queryset() utilities instead.

However, if I create a:

class CustomQuerySet(InheritanceQuerySetMixin, models.QuerySet):
    pass

With an implementation of:

class MyModel(models.Model):
    objects = CustomQuerySet.as_manager()
    # insert fields fields

The resulting MyModel.objects.all() won't return upcasted models.

The reason I use as_manager is I can just keep one QuerySet and avoid duplicating stuff unnecessarily. I think there was an intention to have it implemented this was from a long time ago, but it seems it didn't happen.

Or, I'm wrong, and making a mistake... 😄

@tony
Copy link
Member Author

tony commented Dec 4, 2017

Okay, I read in a bit more deeply:

If you don’t explicitly call select_subclasses() or get_subclass(), an InheritanceManager behaves identically to a normal Manager; so it’s safe to use as your default manager for the model.

MyModel.objects.all().select_subclasses() works as intended. This essentially gives me the behavior of what https://github.com/django-polymorphic/django-polymorphic did.

Two things:

  1. Is there a way to use as_manager to make select_subclasses by default
  2. is there a way to have it so there is a get_subclass in the instance of downcasted MyModel instances?

@Mogost Mogost closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants