3👍
Writing a hierarchical comments application seems too easy at first look but believe me it is not that simple. There are too many edge cases and security issues. So if this is a real project i would suggest you to use disqus, any other hosted solution or (now deprecated) comments framework.
On the other hand if you are just trying to learn how things done or playing around, your code seems fair enough so far. But you should consider Django’s built-in content types framework instead of a direct foreign key relationship. That way you can relate a comment object to any other object. (a blog post or another comment). Take a look at comment frameworks models.py and you will see it.
class BaseCommentAbstractModel(models.Model):
"""
An abstract base class that any custom comment models probably should
subclass.
"""
# Content-object field
content_type = models.ForeignKey(ContentType,
verbose_name=_('content type'),
related_name="content_type_set_for_%(class)s")
object_pk = models.TextField(_('object ID'))
content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk")
Also take a look at RenderCommentListNode
in comment framework template tags. You should write a recursive function in order to get and display hierarchical comments.
You have to consider cases like:
- What will happen if a user deletes a comment?
- How should we delete comments? Should we actually remove it from database or should we set an attribute like
deleted
- How should we deal with permissions and level of user access?
- If we let anonymous users to comment, what information do we need from them.
- How to check human validation? Is captcha enough?
Happy hacking.