コード例 #1
0
ファイル: views.py プロジェクト: zyzone03/pro_magazine
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})
コード例 #2
0
ファイル: views.py プロジェクト: zyzone03/pro_magazine
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})
コード例 #3
0
ファイル: views.py プロジェクト: frmh0313/newmagazine
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, })
コード例 #4
0
ファイル: views.py プロジェクト: chang12/project_150808
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)
コード例 #5
0
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,
    })
コード例 #6
0
ファイル: views.py プロジェクト: garam0130/2015-08-django
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,
        })
コード例 #7
0
ファイル: views.py プロジェクト: chang12/project_150808
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')
コード例 #8
0
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,
    })
コード例 #9
0
ファイル: views.py プロジェクト: frmh0313/newmagazine
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, })
コード例 #10
0
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,
    })