Two types of commenting system in one


How I added comments on my website

Considering the specifics of the "typical commentator" I tried to make commenting on my site as accessible and simple as possible. It was also necessary to add already registered users to this commenting system, which I actually did.

Roughly speaking, the hard part was to take into account both anonymous commentators and registered ones. As if there is no difference in commenting for both of them.


There are 5 goals:

  • Implement a user model
  • Implement comment model
  • Create commenting form for anonymous users
  • Create commenting form for registered ones
  • Combine both of them under one model and one submission form.


User model

Let's start with the simplest goal. The User model. I already had a model of it, since the implementation of the authentication system. Therefore, I will not cover this task.

Comment model

Next comes the comment model. Not everything is simple with him. To keep track of who left the comment, I had to add two IDs. One for anonymous, one for registered user

I also added an additional field, ManyToManyField. And it pointed to the comment model itself. In the future I plan to add the ability to reply to other comments. But that's in the future. For now, let's move on.

Commenting for anonymous

Commenting for anonymous users had to be slightly limited, otherwise spam would be inevitable. They, and even registered users, can post a comment no more than once per minute.

Comment example | Tim the webmaster

Also, before posting a comment, the anonymous user is asked for his name. This is so that you can understand who left the comment.

Comment example with name verification | Tim the webmaster

Collaborative commenting

There is no requirement for registered users. Just leave a comment

It was not difficult to unite both of them under one form. A little javascript and Django template magic. And now, we already have a working commenting system.


I would like to say that there is room for growth in this direction. Take at least the opportunity to leave comments through your social networks or, for example, attach pictures or GIFs to comment.

In general, I quickly made this application for Django. Created the required minimum. It probably took me 8 days to complete it. Not more.

As a result, all the goals were completed and now everyone will be able to leave their signature under any post on my website. Isn't that amazing )

Additional materials

heart 0
3 connected dots 0