예제 #1
0
def comment(request):
    user = get_user(request)
    article_id = request.POST.get('article_id')

    comment = Comment()
    comment.article_id = article_id
    comment.author = user.username
    comment.content = request.POST.get('content')
    comment.save()

    article = Article.objects.filter(id=article_id).first()
    article.comment_count += 1
    article.save()

    message = '评论成功'
    add_message(request, messages.INFO, message)

    current_path = request.POST.get('current_path')
    return HttpResponseRedirect(current_path)
예제 #2
0
파일: views.py 프로젝트: esvfr/my-post
def add_Comment(request, article_id):
    form = CommentForm(request.POST)
    article = get_object_or_404(Article, id=article_id)
    if form.is_valid():
        comment = Comment()
        comment.path = []
        comment.article_id = article
        comment.author_id = auth.get_user(request)
        comment.content = form.cleaned_data['comment_area']
        comment.save()
        try:
            comment.path.extend(
                Comment.objects.get(
                    id=form.cleaned_data['parent_comment']).path)
            comment.path.append(comment.id)
        except ObjectDoesNotExist:
            comment.path.append(comment.id)
        comment.save()

    return redirect(article.get_absolute_url())