Django Comments Documentation, Release 1.8
new comments on objects of that model will be disallowed (immediately deleted) whenever the value of
that field is False on the object the comment would be attached to. Default value is None.
moderate_after
If auto_moderate_field is used, this must specify the number of days past the value of the field
specified by auto_moderate_field after which new comments for an object should be marked non-
public. Allowed values are None, 0 (which moderates comments immediately), or any positive integer.
Default value is None.
Simply subclassing CommentModerator and changing the values of these options will automatically enable the
various moderation methods for any models registered using the subclass.
Adding custom moderation methods
For situations where the options listed above are not sufficient, subclasses of CommentModerator can also override
the methods which actually perform the moderation, and apply any logic they desire. CommentModerator defines
three methods which determine how moderation will take place; each method will be called by the moderation system
and passed two arguments: comment, which is the new comment being posted, content_object, which is the
object the comment will be attached to, and request, which is the HttpRequest in which the comment is being
submitted:
CommentModerator.allow(comment, content_object, request)
Should return True if the comment should be allowed to post on the content object, and False otherwise (in
which case the comment will be immediately deleted).
CommentModerator.email(comment, content_object, request)
If email notification of the new comment should be sent to site staff or moderators, this method is responsible
for sending the email.
CommentModerator.moderate(comment, content_object, request)
Should return True if the comment should be moderated (in which case its is_public field will be set to
False before saving), and False otherwise (in which case the is_public field will not be changed).
Registering models for moderation
The moderation system, represented by django_comments.moderation.moderator is an instance of the
class Moderator, which allows registration and “unregistration” of models via two methods:
moderator.register(model_or_iterable, moderation_class)
Takes two arguments: the first should be either a model class or list of model classes, and the second should
be a subclass of CommentModerator, and register the model or models to be moderated using the options
defined in the CommentModerator subclass. If any of the models are already registered for moderation, the
exception AlreadyModerated will be raised.
moderator.unregister(model_or_iterable)
Takes one argument: a model class or list of model classes, and removes the model or models from the set
of models which are being moderated. If any of the models are not currently being moderated, the exception
NotModerated will be raised.
Customizing the moderation system
Most use cases will work easily with simple subclassing of CommentModerator and registration with the provided
Moderator instance, but customization of global moderation behavior can be achieved by subclassing Moderator
and instead registering models with an instance of the subclass.
1.6. Generic comment moderation 15