I am getting duplicate of each content when updating content from html page. see the picture:
I am not getting any duplicate when updating from Django admin panel. How to avoid duplicate when updating from HTML template?
here is my code
I think I am doing any mistake in my views. here is my views.py
class ApproveCommentPage(UpdateView):
model = BlogComment
template_name = "blog/approve_comment.html"
form_class =AdminComment
def form_valid(self, form):
self.object = form.save()
status = self.object.is_published
name = self.object.name[0:20]
messages.success(self.request, f"{name} comment status {status}")
return super().form_valid(form)
def get_success_url(self):
res = reverse('blog:blog-admin')
if 'page' in self.request.GET:
res += f"?page={self.request.GET['page']}"
return res
#Updating question
here is my notifications.html where rendering all messages:
notifications.html
{% for notification in notifications %}
{%if user.id == notification.blog.author.id %}
{% if notification.notification_type == "Comment Approved" %}
{{ notification.text_preview }}
{%endif%}
{%endif%}
{%endfor%}
notification.views.py
def ShowNOtifications(request):
notifications = Notifications.objects.all().order_by('-date')
template_name ='blog/notifications.html'
context = {
'notifications': notifications,
}
print("##############",context)
return render(request,template_name,context)
my html page where I am updating comment status. By default all comment status “pending” which means unpublished. here I am reviewing every comment and changing their status to “published”. Only getting duplicate when changing status from here. approve_commnet.html
<form method="POST">
{% csrf_token %}
{{form.as_p}}
<button class="btn btn-info">Publish</button>
</form>
When updating comment status from admin panel I am not getting any duplicate. Only getting duplicate When trying to update comment status from approve_commnet.html .