Search code examples
pythondjangodjango-appsdjango-comments

Django comments


I have a Django application with two models: the first one is django.contrib.auth.User and the second one is Product, created by me.

For every product I would add the comments, so every User registered can insert a comment for every product.

I've see there's django.contrib.comments, but probably it's for the blog-like sites, where's every user can leave a comment also if they're not registered. I would a comment form with only the textarea for write the comment and the user is automatically setted to request.user.

Should I write the comments system from scratch?


Solution

  • What you've described sounds extremely simple, and perfect for Django's in-built comment app. Just because it allows anonymous users to comment doesn't mean that's a requirement, you can easily prevent anonymous users from commenting by simply not displaying the comment form for non-authenticated users.

    You should run through this example of using the in-built comment app: https://docs.djangoproject.com/en/dev/ref/contrib/comments/example/

    I think you'll find it does everything you need, has additional features you might not have thought of (spam protection) and will save you a lot of time building something from scratch.