0

我正在使用 django 评论系统,除了评论被添加到表中并且 is_public 设置为 false 之外,一切正常。

有谁知道这是为什么以及如何解决它,即将它们设置为 true

编辑,这是我的代码:

{% load comments %}

<ul>
{% get_comment_list for entry as comment_list %}
{% for c in comment_list %}
<li>{{c.comment|safe|linebreaksbr}} - {{c.user_name}}, <span>left {{ c.submit_date|timesince }} ago)</span></li>
{% empty %}
<li>
   No comments have been added
</li>
{% endfor %}
</ul>

{% get_comment_form for entry as form %}

<form action="{% comment_form_target %}" method="POST">
    {{ form.content_type }}
    {{ form.object_pk }}
    {{ form.timestamp }}
    {{ form.security_hash }}
    <p style="display:none">
      {{ form.honeypot }}
    </p>
    <input type="hidden" name="next" value="/public/blog/post/{{entry.slug}}/" />
            <div class="contentSectionTitleWhite">
                LEAVE COMMENT
            </div>
            <div class="postLeaveReplayContainer">
                <!-- NAME --><span class="commonControlLabel">Your name:</span>&nbsp;<span class="commonControlLabelItalic">(required)</span>
                <span id="postNameErrorMsg" class="commonControlErrorMsg"></span>
                <br/>
                <input class="commonInput" type="text" id="id_name" name="name" />
                <br/>
                <!-- EMAIL --><span class="commonControlLabel">Your email:</span>&nbsp; <span class="commonControlLabelItalic">(required, will not be published)</span>
                <span id="postEmailErrorMsg" class="commonControlErrorMsg"></span>
                <br/>
                <input class="commonInput" type="text" id="id_email" name="email" />
                <br/>
                <!-- MESSAGE --><span class="commonControlLabel">Message:</span>&nbsp;<span class="commonControlLabelItalic">(required)</span>
                <span id="postMessageErrorMsg" class="commonControlErrorMsg"></span>
                <textarea class="commonTextarea" rows="20" cols="20" id="id_comment" name="comment">
                </textarea>
                <br/>
                <!-- SEND BUTTON --><input type="submit" value="Submit" id="postSendButton" class="readViewMoreBtn">

        </form>
4

2 回答 2

1

为了让它工作,我将以下代码添加到我的模型中

def moderate_comment(sender, instance, **kwargs):
    if not instance.id:
        instance.is_public = True

signals.pre_save.connect(moderate_comment, sender=Comment)
于 2010-08-19T14:57:52.617 回答
0

奇怪,因为(至少在 Django 1.2 中)默认设置为 True:

is_public   = models.BooleanField(_('is public'), default=True,
                help_text=_('Uncheck this box to make the comment effectively ' \
                            'disappear from the site.'))

你确定你自己没有在任何视图中明确地将其设置为 False 吗?

还是您使用了通用评论审核?可能使用了自动调节。它在保存新评论之前将 is_public 字段设置为 False(以避免垃圾邮件)

于 2010-08-06T11:47:31.583 回答