Wpisy z kategorii: moderation

django-moderation new release 0.2 - status update

Today i have released new version of django-moderation - 0.2. It has been uploaded in to pypi, so now it can be installed with easy_install.

Many bugs were fixed and many new features were added since initial release.

List of changes

  • Added GenericModerator class that encapsulates moderation options for a given model.Changed register method, it will get only two parameters: model class and settings class.
  • Added option to register models with multiple managers.
  • Added options to GenericModerator class: auto_approve_for_superusers, auto_approve_for_staff, auto_approve_for_groups, auto_reject_for_anonymous, auto_reject_for_groups. Added methods for checking auto moderation.
  • Added automoderate helper function.
  • Changed moderated_object property in ModerationManager class, moderated object is get only once from database, next is cached in moderatedobject, fixed issue with not setting user object on changed_by attribute of ModeratedObject model.
  • Fixed issue when loading object from fixture for model class that is registered with moderation. Now moderated objects will not be created when objects are loaded from fixture.
  • Fixed issue with TypeError when generating differences of changes between model instances that have field with non unicode value ex. DateField.
  • Fixed issue with accessing objects that existed before installation of django-moderation on model class.
  • Fixed issue when more then one model is registered with moderation and multiple model instances have the same pk.
  • Fixed issue with multiple model save when automoderate was used. Auto moderation in save method of ModeratedObject has been moved to separate method.
  • Added admin filter that will show only content types registered with moderation in admin queue.
  • Fixed issue when creating model forms for objects that doesn't have moderated object created.
  • Added possibility of passing changed object in to is_auto* methods of GenericModerator class. This will allow more useful custom auto-moderation. Ex. auto reject if akismet spam check returns True.
  • Added ability to provide custom auto reject/approve reason.
  • Added option bypass_moderation_after_approval in to GenericModerator class that will release object from moderation system after initial approval of object.
  • Other bug fixes and code refactoring.

I would like to thank all persons that had contributed to this project, found bugs, submitted ideas, send patches.

Special thanks to jonwd7 - Thank you for all ideas, bug fixes, patches.

Thank you all very much.

If any body will find any new bugs, please create an issue at github

Announcing django-moderation

django-moderation is reusable application for Django framework, that allows to moderate any model objects.

Code can be found at http://github.com/dominno/django-moderation

Possible use cases:

  • User creates his profile, profile is not visible on site. It will be visible on site when moderator approves it.
  • User changes his profile, old profile data is visible on site. New data will be visible on site when moderator approves it.


  • configurable admin integration(data changed in admin can be visible on site when moderator approves it)
  • moderation queue in admin
  • html differences of changes between versions of objects
  • configurable email notifications
  • custom model form that allows to edit changed data of object
  • 100% PEP8 correct code
  • test coverage > 80%


python >= 2.4

django >= 1.1


Download source code from http://github.com/dominno/django-moderation and run installation script:

$> python setup.py install


  1. Add to your INSTALLED_APPS in your settings.py:


  2. Run command manage.py syncdb

  3. Register Models with moderation

    from django.db import models
    from moderation import moderation
    class YourModel(models.Model):
  4. Register admin class with your Model

    from django.contrib import admin
    from moderation.admin import ModerationAdmin
    class YourModelAdmin(ModerationAdmin):
        """Admin settings go here."""
    admin.site.register(YourModel, YourModelAdmin)

If you want to disable integration of moderation in admin, add admin_intergration_enabled = False to your admin class:

class YourModelAdmin(ModerationAdmin):
    admin_intergration_enabled = False

admin.site.register(YourModel, YourModelAdmin)

How django-moderation works

When you change existing object or create new one, it will not be publicly available until moderator approves it. It will be stored in ModeratedObject model.

your_model = YourModel(description='test')

Traceback (most recent call last):
DoesNotExist: YourModel matching query does not exist.

When you will approve object, then it will be publicly available.

                                   reason='Reason for approve')

<YourModel: YourModel object>

You can access changed object by calling changed_object on moderated_object:

<YourModel: YourModel object>

This is deserialized version of object that was changed.

Now when you will change an object, old version of it will be available publicly, new version will be saved in moderated_object

your_model.description = 'New description'

your_model = YourModel.objects.get(pk=1)
{'id': 1, 'description': 'test'}

{'id': 1, 'description': 'New description'}

                                   reason='Reason for approve')

your_model = YourModel.objects.get(pk=1)
{'id': 1, 'description': 'New description'}

Email notifications

By default when user change object that is under moderation, e-mail notification is send to moderator. It will inform him that object was changed and need to be moderated.

When moderator approves or reject object changes then e-mail notification is send to user that changed this object. It will inform user if his changes were accepted or rejected and inform him why it was rejected or approved.

How to overwrite email notification templates

E-mail notifications use following templates:

  • moderation/notification_subject_moderator.txt
  • moderation/notification_message_moderator.txt
  • moderation/notification_subject_user.txt
  • moderation/notification_message_user.txt

Default context:

content_type - content type object of moderated object

moderated_object - ModeratedObject instance

site - current Site instance

How to pass extra context to email notification templates

If you want to pass extra context to email notification methods you new need to create new class that subclass BaseModerationNotification class.

class CustomModerationNotification(BaseModerationNotification):
    def inform_moderator(self,
        '''Send notification to moderator'''
        super(CustomModerationNotification, self).inform_moderator(subject_template,

    def inform_user(self, user,
        '''Send notification to user when object is approved or rejected'''
        super(CustomModerationNotification, self).inform_user(user,

Next register it with moderation as notification_class:

moderation.register(YourModel, notification_class=CustomModerationNotification)


moderation.signals.pre_moderation - signal send before object is approved or rejected

Arguments sent with this signal:

sender - The model class.

instance - Instance of model class that is moderated

status - Moderation status, 0 - rejected, 1 - approved

moderation.signals.post_moderation - signal send after object is approved or rejected

Arguments sent with this signal:

sender - The model class.

instance - Instance of model class that is moderated

status - Moderation status, 0 - rejected, 1 - approved


When creating ModelForms for models that are under moderation use BaseModeratedObjectForm class as ModelForm class. Thanks to that form will initialized with data from changed_object.

from moderation.forms import BaseModeratedObjectForm

class ModeratedObjectForm(BaseModeratedObjectForm):

    class Meta:
        model = MyModel

Any comments ? Feedback ? Feature requests ?