Search code examples
djangodjango-comments

How to automatically accept comments from authenticated users in django.contrib.comments


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.


Solution

  • 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)