I am trying to add reply functionality. Basically it will be parent child relationship. I am trying to do this by passing parent foreign key value as hidden input in my reply from. But all reply are posting as a parent comment.
{% for q in queryset %} #I am using queryset for review every commnet before it showing in my html template.
name: {{q.name}}
comment:{{q.commnet}}
replay to this commnet:
{% csrf_token %}
<input type="hidden" name="parent_id" value="{{q.parent}}"> #passing parent foreign key value as hidden input.
<input type="text" name="name" class="form-control" placeholder="Your Name" required>
<input type="email" name="email" class="form-control" placeholder="Enter email" required>
<textarea class="form-control" name="comment" id="exampleFormControlTextarea1" rows="3">
</textarea>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
{% endfor %}
views.py
def post(self,request,slug):
blog = Blog.objects.get(slug=slug)
form = CommentFrom(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.blog = blog
comment.save()
messages.add_message(self.request, messages.INFO, 'Your Comment pending for admin approval')
return redirect(reverse('blog-detail', kwargs={'slug':slug}))
else:
form()