Search code examples
djangodjango-comments

django comments why is the field is_public being set to false


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>&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>

Solution

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