def comment_reply(request, type, parent_id): parent_comment = Comment.objects.get(id=parent_id) response = {} if not parent_comment: response['error'] = 'Parent comment not found' if request.POST: form = CommentForm(request.POST) if form.is_valid(): comment = CommentForm(request.POST).save(commit=False) comment.thread_id, comment.reverse_thread_id = \ get_thread_id(type, parent_comment.thing_id, parent_comment) comment.author = request.user comment.thing_id = parent_comment.thing_id comment.type = type comment.parent_id = parent_comment.id comment.save() response['content'] = Markup.unescape( Markup( render_to_string(request, 'comments/comment.html', {'comment': comment}) ) ) return render_to_remote_response(request, json_context=response)