2π
I assume you are using session authentication.
You can do it in several ways.
First, you can add an extra field in your comments API
by doing something like this:
comments['editable'] = request.user.user_name == comment.author_name
If it is True, user can edit the comment and vice versa. I believe this is a better way.
Second way is directly in your script get access to django user and compare there:
<script>
var editable = comment.author_name == {{ request.user.user_name }}
</script>
This is not a good approach. Because you are mixing django variable with jquery! If your script is in another file, it wonβt work at all.
So, I would go with the first way.
Hope it helps
0π
In your templates:
<script>
var reply_name = {{ request.user.user_name }};
get_comment(repay_name) #call what you want using js
</script>
π€Windsooon
- [Answered ]-Regex email validation django
- [Answered ]-When using Q objects in django queryset for OR condition error occured
- [Answered ]-Django template if inside a for loop β Invalid block tag on line 13: 'else', expected 'empty' or 'endfor'.
- [Answered ]-How to label a form instance within a django inline formset?
- [Answered ]-Django-Fluent-Comments β NoReverseMatch at /rohit/post/new/
Source:stackexchange.com