django:默认情况下如何使django评论不公开

时间:2010-04-02 14:14:44

标签: django django-comments

使用django评论框架http://docs.djangoproject.com/en/dev/ref/contrib/comments/

不确定是否有选项,在所有评论通过审核之前使其非私密... 看起来我的所有评论都是在发布之后添加到网站上的。真的需要改变这个

2 个答案:

答案 0 :(得分:4)

执行此操作的一种方法是编写自己的注释表单,该表单继承自django.contrib.comments.forms.CommentForm并重写其get_comment_create_data函数。警告:此代码未经过测试。

from django.contrib.comments.forms import CommentForm

class MyCommentForm(CommentForm):
    def get_comment_create_data(self):
        data = super(MyCommentForm, self).get_comment_create_data()
        data['is_public'] = False
        return data

然后,您可以将此表单挂钩到注释系统中,如本节所述 http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/

答案 1 :(得分:3)

设置评论主持人并将'auto_moderate_field'设置为模型上的DateField或DateTimeField,并将'moderate_after'设置为0。

class ArticleModerator(CommentModerator):
    email_notification = True
    enable_field = 'enable_comments'
    auto_moderate_field = 'pub_date'
    moderate_after = 0

moderator.register(Article, ArticleModerator)

文档中的更多信息: https://docs.djangoproject.com/en/dev/ref/contrib/comments/moderation/#built-in-moderation-options

相关问题