Is there a way to make Django automatically set the is_public field of the comment as True.
I only allow comments for registered users and would like to skip manual review of comments posted.
Is there a way to make Django automatically set the is_public field of the comment as True.
I only allow comments for registered users and would like to skip manual review of comments posted.
The built in comments form should already set every comment to have is_public=True. See CommentDetailsForm.get_comment_create_data
in http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/forms.py
If you want to change this for logged in vs not logged in users, take a look at the built in comment moderation docs: http://docs.djangoproject.com/en/1.1/ref/contrib/comments/moderation/#ref-contrib-comments-moderation
You can write your own moderator which checks the comment to see if the comment.user is set and if it is do not moderate (is_public=True) otherwise set is_public=False.
OK if anyone is looking for the answer for this, this is how I solved it:
# in models.py:
import datetime
def moderate_comment(sender, instance, **kwargs):
if not instance.id:
instance.is_public = True
from django.contrib.comments.models import Comment
from django.db.models import signals
signals.pre_save.connect(moderate_comment, sender=Comment)
Overriding the moderate
of CommentModerator works for me:
from django.contrib.comments.moderation import CommentModerator
class EntryModerator(CommentModerator):
# [...]
def moderate(self, comment, content_object, request):
# If the user who commented is a staff member, don't moderate
if comment.user and comment.user.is_staff:
return False
else:
return True