django 评论为什么 is_public 字段被设置为 false

发布于 2024-09-13 07:54:27 字数 2483 浏览 9 评论 0原文

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

有谁知道这是为什么以及如何修复它,即将它们设置为真正的

编辑,这是我的代码:

{% 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>

I am using the django comments system and everything is working ok apart from the comments are being added into the table with is_public being set to false.

Does anyone know why this is and how I can fix it, i.e. have them set as true

edit, this is the code I have:

{% 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> <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>  <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> <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺渁∝ 2024-09-20 07:54:27

为了使其正常工作,我将以下代码添加到我的模型中

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

signals.pre_save.connect(moderate_comment, sender=Comment)

To get this to work I added the following code to my model

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

signals.pre_save.connect(moderate_comment, sender=Comment)
嗳卜坏 2024-09-20 07:54:27

奇怪,因为(至少在 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 吗?

或者您是否使用了 通用评论审核?可能是 auto使用节制。它在保存新评论之前将其 is_public 字段设置为 False (以避免垃圾邮件)

strange, because (at least in Django 1.2) the default is set to True:

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

Are you shure you do not explicity set it to False in any view yourself?

Or did you use the Generic comment moderation? Possibly the auto moderation is used. It set the is_public field of new comments to False before saving them (To avoid Spam)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文