def comment_edit(request, post_pk, pk): comment = get_object_or_404(Comment, pk=pk) if request.method == "POST": form = CommentForm(request.POST, instance=comment) if form.is_valid(): form.save() return redirect("magazine:article_detail", post_pk) else: form = CommentForm(instance=comment) return render(request, "magazine/comment_new.html", {"form": form})
def comment_new(request, post_pk): if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.article = get_object_or_404(Article, pk=post_pk) comment.save() messages.success(request, "댓글이 등록되었습니다.") return redirect("magazine:article_detail", post_pk) else: form = CommentForm() return render(request, "magazine/comment_new.html", {"form": form})
def comment_edit(request, category_pk, article_pk, pk): comment = get_object_or_404(Comment, pk=pk) if request.method == 'POST': form = CommentForm(request.POST, instance=comment) if form.is_valid(): comment = form.save(commit=False) comment.artcle = get_object_or_404(Article, pk=article_pk) comment.save() messages.debug(request, 'Comment edited') return redirect('magazine.views.article_detail', category_pk, article_pk) else: form = CommentForm(instance=comment) return render(request, 'magazine/comment_form.html', {'form': form, })
def comment_edit(request, post_pk, pk): post = get_object_or_404(Post, pk=post_pk) comment = post.comment_set.get(pk=pk) if request.method == 'POST': form = CommentForm(request.POST, instance=comment) if form.is_valid(): form.save() return redirect('magazine:detail', pk=post_pk) else: form = CommentForm(instance=comment) params = { 'form': form, } return render(request, 'magazine/form.html', params)
def post_detail(request, pk): post = get_object_or_404(Post, pk=pk) comment_form = CommentForm() return render(request, 'magazine/post_detail.html', { 'post': post, 'comment_form': comment_form, })
def comment_new(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) messages.info(request, "새 댓글이 등록되었습니다") comment.post = post comment.save() return redirect('magazine:detail',pk) else: form = CommentForm() return render(request, "magazine/forms.html", { 'form':form, })
def comment_new(request, pk): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): post = get_object_or_404(Post, pk=pk) comment = form.save(commit=False) comment.post = post comment.save() if request.is_ajax(): params = { 'comment': comment, } return render(request, 'magazine/comment_row.html', params) else: return redirect('magazine:detail', pk) else: return render(request, 'magazine/error.html')
def comment_edit(request, post_pk, pk): comment = get_object_or_404(Comment, pk=pk) if request.method == 'POST': form = CommentForm(request.POST, instance=comment) if form.is_valid(): form.save() messages.success(request, '댓글을 수정했습니다.') return redirect('magazine:post_detail', comment.post.pk) else: form = CommentForm(instance=comment) return render(request, 'form.html', { 'form': form, 'post': comment.post, })
def comment_new(request, category_pk, article_pk): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.article = get_object_or_404(Article, pk=article_pk) # comment.article.category.pk = category_pk comment.save() messages.debug(request, 'New Comment posted') form.save() return redirect('magazine.views.article_detail', category_pk, article_pk) else: form = CommentForm() return render(request, 'magazine/comment_form.html', {'form': form, })
def comment_new(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() if request.is_ajax(): return render(request, 'magazine/comment_row.html', { 'comment': comment, }) else: messages.success(request, '새로운 댓글을 저장했습니다.') return redirect('magazine:post_detail', post.pk) else: form = CommentForm() return render(request, 'form.html', { 'form': form, 'post': post, })