Closed swiharta closed 12 years ago
You should be able to hook the post_moderation
signal and use the moderated_object
property to find the previous version of the object and restore it.
Here's an example of how you might do it (I have not tested this code):
def post_moderation_handler(sender, instance, status, **kwargs):
if status == 0: # Rejected
instance.moderated_object.changed_object.save() # Save previous version
post_moderation.connect(post_moderation_handler, dispatch_uid="post_moderation_handler")
Thanks for the tip, Trey. I'll give it a try and report back.
@swiharta does this answer solves your problem ? This could be also solved when moderation history will be implemented. Its described in #21
I honestly have been too busy to test Trey's suggestion, but I think it sounds like it will work fine, so I'll close this, thanks for reminding me. Looking forward to the moderation history also!
I may be doing something incorrect, but I tested this code and it's not working for me. When I reject an object, it actually saves the new (rejected) version and displays it publicly. Without this signal, however, everything is working correctly.
It would be a nice feature if, in the case that you are making a change to an existing moderated model instance, on approving the change, the previous model instance got stored in ModeratedObject.changed_object, so that if you subsequently rejected the change, that previous instance could be reinstated, just swapping changed_object for the model instance.