Exemplo n.º 1
0
def comment(request):
    form = CommentForm(request.POST)
    if form.is_valid():
        content = form.cleaned_data.get('content')
        articleId = form.cleaned_data.get('article_id')
        articleModel = ArticleModel.objects.filter(pk=articleId).first()
        if articleModel:
            commentModel = CommentModel(content=content, article=articleModel, author=request.front_user)
            commentModel.save()
            return redirect(reverse('front_article_detail', kwargs={'article_id': articleId}))
        else:
            return myjson.json_params_error(message=u'没有这篇文章')
    else:
        return myjson.json_params_error(message=form.get_error())
Exemplo n.º 2
0
def comment(request):
    form = CommentForm(request.POST)
    if form.is_valid():
        content = form.cleaned_data.get('content')
        articalId = form.cleaned_data.get('artical_id')
        articalModel = ArticalModel.objects.filter(pk=articalId).first()
        print articalModel
        if articalModel:
            commentModel = CommentModel(content=content,
                                        artical=articalModel,
                                        author=request.front_user)
            commentModel.save()
            return redirect(
                reverse('front_artical_detail', kwargs={'code': articalId}))
            # return xtjson.json_result()
    else:
        return xtjson.json_params_error(message=form.get_error())