Django comments fields

Upon reading the nice documentation for the new comment framework in django 1.0, one might wonder what are the fields attached to the comment entity which you are to iterate against:

{% for comment in comment_list %}
     ...
{% endfor %}

There’s something wrong in that code. The ellipsis!
So what should you write in there? There’s no mention of the comment fields in the docs, so I put on my rubber boots and got down to my dbshell so you don’t have to.

revolution=> \d+ django_comments
                                             Table "public.django_comments"
     Column      |           Type           |                          Modifiers                           | Description 
-----------------+--------------------------+--------------------------------------------------------------+-------------
 id              | integer                  | not null default nextval('django_comments_id_seq'::regclass) | 
 content_type_id | integer                  | not null                                                     | 
 object_pk       | text                     | not null                                                     | 
 site_id         | integer                  | not null                                                     | 
 user_id         | integer                  |                                                              | 
 user_name       | character varying(50)    | not null                                                     | 
 user_email      | character varying(75)    | not null                                                     | 
 user_url        | character varying(200)   | not null                                                     | 
 comment         | text                     | not null                                                     | 
 submit_date     | timestamp with time zone | not null                                                     | 
 ip_address      | inet                     |                                                              | 
 is_public       | boolean                  | not null                                                     | 
 is_removed      | boolean                  | not null                                                     | 
Indexes:
    "django_comments_pkey" PRIMARY KEY, btree (id)
    "django_comments_content_type_id" btree (content_type_id)
    "django_comments_site_id" btree (site_id)
    "django_comments_user_id" btree (user_id)
Foreign-key constraints:
    "django_comments_content_type_id_fkey" FOREIGN KEY (content_type_id) REFERENCES django_content_type(id) DEFERRABLE INITIALLY DEFERRED
    "django_comments_site_id_fkey" FOREIGN KEY (site_id) REFERENCES django_site(id) DEFERRABLE INITIALLY DEFERRED
    "django_comments_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
Has OIDs: no

So here’s how a simple django template with comments would look like, the relevant part:

{% get_comment_count for post as comment_count %}
{% get_comment_list for post as comment_list %}

You can play with the is_public and is_removed fields in the admin site and you can also modify any other fields in your users’ posts. You could also use the ip_address field to display country flags in your comments .

The django comments provide a spam-fighting technique by default, in the form of a honeypot (though I wonder how effective that is) as well as other extras. There are rumours that some sort of captcha system (some say reCaptcha ) will be integrated in the django comments framework.

Take more risks! Live more dangerously!


Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.