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

overtaking _default_manager #199

Open
grucha opened this issue Apr 26, 2021 · 0 comments
Open

overtaking _default_manager #199

grucha opened this issue Apr 26, 2021 · 0 comments

Comments

@grucha
Copy link

grucha commented Apr 26, 2021

I have a use case where I don't want the mdoel._default_manager to be moderated.

I am limiting moderation-affected querysets by Moderator.manager_names and I am using moderated managers explicitly in my code only where I need them.

Unfortunately, regrdless of limiting via manager_names, django-moderation overtakes the model._default_manager and I can not create objects with foreign key to moderated model for objects that haven't been approved yet (having visible=False).

Here is a sketch of my models:

class Artwork(ModeratedModel, models.Model):
    objects = models.Manager()
    moderated_objects = models.Manager()  # only this one should be moderated

    class Meta:
        manager_names = ["moderated_objects"]  # I don't want `objects` to be affected, i.e. the default manager too!
        visibility_column = "visible"

class Photo(models.Model):
    artwork = ForeignKey(Artwork)

And the usage:

>>> artwork = Artwork.objects.create()  # has visible = False, is excluded from moderated queryset
>>> photo = Photo.objects.create(artwork=artwork)
Traceback (most recent call last):
  File "...."
ArtworkDoesNotExist: ...

This happens because django validates Photo.artist field with Artist's _default_manager: https://docs.djangoproject.com/en/3.2/topics/db/managers/#django.db.models.Model._default_manager which is moderated, thus fails (until artist was approved).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant