Version 3 (modified by coulix, 9 years ago) (diff)

fix to comments

Using the FreeComment application integrated to Django.

Edit your and add an import

from django.contrib.comments.models import FreeComment

Edit your


In your html template you can use the comment system. Remember a comment is going to be link to an entry id , for any of your model, it could be a blog post or a recipe. Add this to your template file

{% load comments %}

to display the comments for the current entry wich is a recipe object r. recettes is the app name recipe the model in

{% get_free_comment_list for recettes.recipe as comment_list %}
{% if comment_list %}
    {% for comment in comment_list %}
         {{ comment.person_name }}
         {{ comment.submit_date|date:"j F, Y" }} 
         {{ comment.submit_date|date:"P" }}
         {{ comment.comment|escape|urlizetrunc:40|linebreaks }} 
    {% endfor %}
{% endif %}

Here is a larger example where you cycle throught 2 colors to display the comments.

{% get_free_comment_list for recettes.recipe as comment_list %}
{% get_free_comment_count for recettes.recipe as comment_count %}
{% if comment_list %}
	<h3>Comments ({{comment_count}})</h3>
	<br />
	{% for comment in comment_list %}
		<div class="{% cycle comment_even,comment_odd %}"  id="c{{forloop.counter}}">
		<div class="comment_content">
        		<span class="comnum"><a id="{{forloop.counter}}" href="#c{{forloop.counter}}">#{{forloop.counter}}</a></span>
                <p>by<b> {{ comment.person_name }}</b>, the{{ comment.submit_date|date:"j F, Y" }} at {{ comment.submit_date|date:"P" }}</p>
                {{ comment.comment|escape|urlizetrunc:40|linebreaks }} 
	{% endfor %}
{% endif %}

We have to append a submit comment form to this.

Add a comment
{% free_comment_form for recettes.recipe %} 

To use our own comments template, create a comments folder into your template folder location In my case /home/greg/projects/cefinban/templates/comments There you could put your own freeform.html, free_preview.html, posted.html. freeform.html is locared in /django/contrib/comments/template/comments


{% load i18n %}
{% if display_form %}
<form action="/comments/postfree/" method="post">
<p>{% trans "Your name:" %} <input type="text" id="id_person_name" name="person_name" /></p>
<p>{% trans "Comment:" %}<br /><textarea name="comment" id="id_comment" rows="10" cols="60"></textarea></p>
<input type="hidden" name="options" value="{{ options }}" />
<input type="hidden" name="target" value="{{ target }}" />
<input type="hidden" name="gonzo" value="{{ hash }}" />
<p><input type="submit" name="preview" value="{% trans "Preview comment" %}" /><input type="submit" name="post" value="{% trans "Submit" %}" /></p>
{% endif %}
Back to Top