I am using django comment framework. It says it provides a lot of functionality, and I can also see in the source files that there are various options, but the documentation is a bit poor.
There are two issues
delete button
for each comment that is posted, and I don't want to redirect the user to another page. I just want the comment to be deleted with a confirmation message. I have not found any documentation that tells me how I can do this in the django comments framework
error while submitting the comment form
, the user is redirected to the preview page
(that handles errors also), I don't want this. I want the user to be redirected to the same page, with the appropriate errors. How can I go about doing this.Any help or direction is appreciated
There is already a delete view for comments but it is a part of the moderation system. You would need to allow all users the can_moderate
permission which would obviously allow them to remove any comment they want (not just theirs). You can quickly write your own view that checks that the comment they are deleting belongs to them:
from django.shortcuts import get_object_or_404
from django.contrib.comments.view.moderate import perform_delete
def delete_own_comment(request, comment_id):
comment = get_object_or_404(Comment, id=comment_id)
if comment.user.id != request.user.id:
raise Http404
perform_delete(request, comment)
and in your template
{% for comment in ... %}
{% if user.is_authenticated and comment.user == user %}
{% url path.to.view.delete_comment comment_id=comment.id as delete_url %}
<a href="{{ delete_url }}">delete your comment</a>
{% endif %}
{% endfor %}
For the second problem, you can see that the redirection will always happen if there are errors (even if preview=False is set). There aren't too many workarounds. You could create your own view that wraps the post_comment
view (or just write your own post_comment withouth the redirection)