本文整理汇总了Python中blog.models.Comment.create_date方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create_date方法的具体用法?Python Comment.create_date怎么用?Python Comment.create_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.create_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import create_date [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)