本文整理汇总了Python中blog.models.Comment.comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.comment方法的具体用法?Python Comment.comment怎么用?Python Comment.comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.comment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_article
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
def get_article(request,slug):
try:
article=Article.objects.get(slug=slug)
except ObjectDoesNotExist:
return HttpResponseRedirect('/')
try:
comments=Comment.objects.filter(article=article).order_by('-date','-id')
except ObjectDoesNotExist:
comments=None
if request.method == 'POST':
form = CommentForm(request.POST, **{'article':article,'ip':request.META['REMOTE_ADDR'],})
if form.is_valid():
comment=Comment()
comment.comment = form.cleaned_data['comment']
comment.article = article
if request.user.is_authenticated():
comment.user = request.user
comment.ip=request.META['REMOTE_ADDR']
comment.save()
return HttpResponseRedirect('/'+article.slug)
else:
form = CommentForm()
return render_to_response('blog/article.html', {
'form': form,
'article': article,
'comments':comments,
},context_instance=RequestContext(request))
示例2: comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
def comment(request, id):
"""
Add a comment to blog
"""
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
data = form.cleaned_data
comment = Comment()
comment.comment = data['comment']
comment.blog_id = id
comment.user_name = data['user_name']
comment.email = data['email']
comment.source_address = request.META['REMOTE_ADDR']# '192.168.2.8'
comment.create_date = datetime.datetime.now()
comment.save()
blog = Blog.objects.get(id=id)
if blog.comment_count is None:
blog.comment_count = 0
blog.comment_count += 1
blog.save()
if request.user.is_authenticated():
return HttpResponseRedirect('/adminshow/%s/' % id)
else:
return HttpResponseRedirect('/show/%s/' % id)
else:
blog = Blog.objects.get(id=id)
comments = Comment.objects.filter(blog_id=id)
return render_to_response('artical.html', {'blog' : blog, 'comments' : comments, 'form' : form}, context_instance=RequestContext(request, processors=[new_blog, blog_group]))
else:
return HttpResponseRedirect('/show/%s/' % id)
示例3: post
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
def post(self, request, *args, **kwargs):
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
comment = Comment()
comment.author = request.user
comment.comment = comment_form.cleaned_data['comment']
comment.post = self.get_post(**kwargs)
comment.save()
return self.get(request, *args, **kwargs)
else:
return self.get(request, *args, **kwargs)