I'm using Django 1.8 to create an application and I'm using django_comments
application to handle commenting system. I want only authenticated users to be able to write a new comment. So I've excluded name
, email
and url
fields in forms.py since I want them to be hidden and retrieve these info automatically from logged in users:
class CommentDetailsForm(CommentSecurityForm):
exclude = ('name', 'email', 'url')
comment = forms.CharField(...)
But there's a function in CommentDetailsForm class to save these info in a dictionary to show them in Admin area:
def get_comment_create_data(self):
return dict(
content_type=ContentType.objects.get_for_model(self.target_object),
object_pk=force_text(self.target_object._get_pk_val()),
user_name=self.cleaned_data["name"],
user_email=self.cleaned_data["email"],
user_url=self.cleaned_data["url"],
comment=self.cleaned_data["comment"],
submit_date=timezone.now(),
site_id=settings.SITE_ID,
is_public=True,
is_removed=False,
)
My question is: How can I fill user_name
, user_email
and user_url
in this function automatically when a logged in user post a new comment.
I guess one solution may be put something like <input type="hidden" name="user_name" value="{{ request.user.username }}" />
in template, but I'm not sure how to do it.