def postDetail(request, column_id, post_id): if request.method == 'GET': column = get_object_or_404(Column, pk=column_id) post = get_object_or_404(Post, pk=post_id) comments_list = Comment.objects.filter(post=post) context = { 'column': column, 'post': post, 'comments_list': comments_list, 'comments_num': comments_list.all().count() } return render(request, "PostPage.html", context) else: post = Post.objects.get(id=post_id) author = User.objects.get(pk=request.user.id) errors = [] content = request.POST.get("content", "") comment = Comment() comment.post = post comment.author = author comment.content = content comment.save() return HttpResponseRedirect( reverse_lazy('forum:post_detail', kwargs={ 'column_id': column_id, 'post_id': post_id }))
def CommentView(request, pk): if request.method == 'POST': post = get_object_or_404(Post, pk=pk) post.views -= 1 post.save() text = request.POST.get('text') if (text == ''): return HttpResponseRedirect(reverse('forum:single', args=(pk, ))) comment = Comment() comment.post = post comment.text = text comment.author = get_object_or_404(Profile, user=request.user) comment.number = str(comment.post.comment_set.all().count() + 1) comment.save() return HttpResponseRedirect(reverse('forum:single', args=(pk, )))