0

I'm using Django's comment framework as a part of my project. With default settings, anonymous users can make comments at will.

I want to change this feature such that only authenticated users can post comments. Moreover, I want this authenticated user's name to show up next to the comment.

How do I go about doing so? I've read up on the documentation, and I understand the pre-defined comment model has a "user" field which is a ForeignKey to the User model / user who posted the comment (Link here). However, I don't understand how to assign request.user (i.e. the current authenticated user) to this user field that belongs to the instance of the comment.

In other words, how does Django process the form data on the front-end to the Comment model in the back-end, and how can I edit this process such as to assign request.user to the user field in the comment model.

Thanks for the help!

goelv
  • 2,774
  • 11
  • 32
  • 40

1 Answers1

0

Start from the documentation

Basically you need to (at least):

  1. enable django.contrib.auth in your settings.py
  2. define login view
  3. use @login_required decorator on the views you want restrict
  4. check if request.user.is_authenticated() in your form processing code.
Kimvais
  • 38,306
  • 16
  • 108
  • 142
  • This applies to regular authentication. How do I apply this technique to the Comment Framework specifically? This framework is defined by Django behind-the-scenes so I don't know how to change specific processes. – goelv Aug 15 '12 at 19:38
  • Is there a reason why you could not use regular authentication? (Both are shipped by default in `django.contrib` - so I'm sure they play together nicely) – Kimvais Aug 16 '12 at 05:09