示例#1
0
 def post(self, request, post_title):
     post = Post.objects.filter(slug=post_title)[0]
     comment = Comment()
     comment.post = post
     comment.text = request.POST['text']
     if isinstance(request.user, User):
         comment.author = request.user
         comment.save()
     else:
         form = NewCommentForm(request.POST)
         if form.is_valid():
             comment.save()
     return redirect('/post/' + post.slug)
示例#2
0
def article(request, id_post):
    post = Post.objects.get(pk=id_post)
    if request.method == 'POST':
        content = request.POST['comment-content']
        comment = Comment()
        comment.author = User.objects.get(pk=request.user.id)
        comment.post = post
        comment.content = content
        comment.approved = True
        comment.save()
    context = RequestContext(request)
    comments = Comment.objects.filter(post=post)
    context['post'] = post
    context['comments'] = comments
    return render_to_response("post.html", context)