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 90 forks source link

Using signals causes not saving moderation status #79

Closed rocchidavide closed 11 years ago

rocchidavide commented 11 years ago

In my model I have a is_visible bool field, set False by default. I want to set it True when the object is approved and set to False if rejected, so I thought to use signals.

from moderation.signals import pre_moderation
from moderation.models import MODERATION_STATUS_APPROVED, MODERATION_STATUS_PENDING, MODERATION_STATUS_REJECTED

def moderation_callback(sender, instance, status, **kwargs):
    if status == MODERATION_STATUS_APPROVED:
        instance.is_visible = 1

    elif status == MODERATION_STATUS_PENDING or status == MODERATION_STATUS_REJECTED:
        instance.is_visible = 0
    instance.save()

pre_moderation.connect(moderation_callback)

The problem is that in admin moderation objects list, moderation status keeps to be pending, as if it doesn't saved; is_visible field is updated well.

Do I something wrong in the saving process?

EDIT

I noted that if I mark object as Rejected, moderation status is 'rejected'; if I mark it as Pending or Approved, moderation status is always 'pending'.. I am a bit confused. Thank you

dominno commented 11 years ago

You dont have to use signals for this. is_visible will be changed automatically.

All you have to do is set visibility_column in moderator class

https://github.com/dominno/django-moderation#genericmoderator-options