dominno / django-moderation

django-moderation is reusable application for Django framework, that allows to moderate any model objects.
BSD 3-Clause "New" or "Revised" License
269 stars 91 forks source link

There is no unmoderated_objects attribute available #84

Closed amyth closed 10 years ago

amyth commented 10 years ago

I went through the documentation and am trying to use django-moderation with one of my applications but not able to get it to work.

I have registered the model with moderator as follows.

from moderation import moderation
from moderation.moderator import GenericModerator

import app.models as SomeModel

class SomeModelModerator(GenericModerator):
    """ Represents a moderator object.
    """

    notify_user = False
    auto_approve_for_superusers = True
    auto_approve_for_staff = True
    manager_names = ['public']

moderation.register(models.Job)

Have the following managers defined in the model:

class SomeModel(models.Model):

    objects = models.Manager()
    public = ModerationObjectsManager()

Am also using admin so I have inherited the admin from ModerationAdmin

In one of the methods I want to get access to all the objects irrespective of if it has been approved or not i.e. I want to bypass moderation.

Documentation states:

Please note that you can also access objects that are not approved by using unmoderated_objects manager, this manager will bypass the moderation system

YourModel.unmoderated_objects.get(pk=your_model.pk)

But there is no attribute named unmoderated_objects available on the SomeModel.

Moreover, from what I understand, if I use manager_names in the moderator object only the specified manager_names should be overridden in which case I should actually be able to access all the objects using SomeModel.objects and moderated objects while using SomeModel.public but that is not the case. Both the managers are being overridden for some reason.

Is there something I am doing wrong ? Howcome the unmoderated_objects manager is not available on my model ?

dominno commented 10 years ago

You dont have to set

public = ModerationObjectsManager()

and

manager_names = ['public']

Remove it and it should be ok.

manager_names should be used when you want to enable moderation on different managers then objects

dominno commented 10 years ago

You can also set model as

class SomeModel(models.Model):

objects = models.Manager()
public =  models.Manager()

class SomeModelModerator(GenericModerator): """ Represents a moderator object. """

notify_user = False
auto_approve_for_superusers = True
auto_approve_for_staff = True
amyth commented 10 years ago

@dominno Thanks for your quick response. Yes, it does work, Though, the unmoderated_ is not available via the shell (that's what confused me the most), maybe because while accessing the shell the Model is not registered with moderation app.