Django site comments and all!


I haven’t been posted that much here recently and thats because I have been doing other things and working on other sites. I have also built a new server for home, which will be detailed later, but first and foremost I am still playing with Django and build a site using it.

I have had enough with doing WordPress sites, and although I do know it fairly well I wanted to write something a bit more tailored to the application. And its a good test for the plans I have for other applications later on.

Django I am enjoying, but its not with out frustration. And although in parts it is amazingly well documented for a framework thats been in the public eye for a relatively shorttime it does miss out on the docs in some parts. I am finding that some things are overdocumented and its hard to find relatively simple bits of information and others such as the comment system just isn’t documented.

Although they are quite upfront about the comment system needing documents, it is an area that slows down the production pipeline quite alot, to the point where its as slow going as any other development. I suppose I can’t complain too much but still I hope this gets addressed reasonably quickly. I should put down my own experiences with the comment system at this point for others to use, but it should be noted that I don’t know much at all and this is only my findings and what I have so far:

  1. The Django comment system is broken up into three areas – Comments, Karma and Freecomment and if you are interested in what these contain then looking at the database should be your first port of call.
  2. Free comments and comments are different though in some cases if you are using a template or method using free_ then you can sometimes safely omit free_ and get the standard comment system.
  3. The standard comment system is based around logged on users, while freecomments seems to be open to all.
  4. At the moment due to the lack of documentation the two best places to find out information is from the django source itself /django/contrib/comments and in the sourcecode posted by Jeff Croft for his Lost-Theories website.

Here you can see the django comments tables in MySQL (my host doesn’t yet support PostGreSQL, so I develop in the same database I am going to host on).

MySQL view of the comments system{.imagelink}

So this has lead me to get a working but rough comments module into my test site. I am using a mixture of my own views and generics like most, and I have created my own templates for the tables in my model.

In the details page for one model, I am pulling out some information from the post like so:

{% block content %}
{{ object.article_body|escape|linebreaks }}
{% endblock %}

Then I am referring to the comments. My model is called Post so that is what I am pulling the comments out for:

{% block metacontent %}
{% load comments.comments %}
{% get_comment_list for as comment_list %}
{% ifequal post.get_comment_count 0 %}
No one has posted any comments yet. Perhaps you'd like to be the first?
{% endifequal %}
{% for comment in comment_list %}
{{ comment.comment }}
{% endfor %}

Then I pull in the standard comment form:

{% comment_form for}

In your templates directory you can then create a subdirectory called “comments” and the commenting system will search in here first for the comments templates before using its own.

I copied the form.html template in here and modified it, and then I also created templates for posted.html and preview.html. If you are looking for ideas for these two again Jeff Croft’s source code for Lost-Theories is very helpful.

And this is as far as I have got so far. In the future I would love to extend it with the Karma system but there is alot more to do to get this site up and running.

comments powered by Disqus