当前位置: 首页>>代码示例>>Python>>正文


Python Comment.post方法代码示例

本文整理汇总了Python中blog.models.Comment.post方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.post方法的具体用法?Python Comment.post怎么用?Python Comment.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.Comment的用法示例。


在下文中一共展示了Comment.post方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_creating_a_new_comment_and_saving_it_to_the_database

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
 def test_creating_a_new_comment_and_saving_it_to_the_database(self):
     # start by create one Category and one post
     category = Category()
     category.name = "First"
     category.slug = "first"
     category.save()
     
     # create new post
     post = Post()
     post.category = category
     post.title = "First post"
     post.content = "Content"
     post.visable = True
     post.save()
     
     # create one comment
     comment = Comment()
     comment.name = "John"
     comment.content = "This is cool"
     comment.post = post
     
     # check save
     comment.save()
     
     # now check we can find it in the database
     all_comment_in_database = Comment.objects.all()
     self.assertEquals(len(all_comment_in_database), 1)
     only_comment_in_database = all_comment_in_database[0]
     self.assertEquals(only_comment_in_database, comment)
     
     # and check that it's saved its two attributes: name and content
     self.assertEquals(only_comment_in_database.name, comment.name)
     self.assertEquals(only_comment_in_database.content, comment.content)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:35,代码来源:models.py

示例2: handle

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
    def handle(self, *args, **options):
        print 'start'
        Comment.objects.all().delete()
        Post.objects.all().delete()
        Topic.objects.all().delete()
        t = Topic()
        t.name = 'Angular'
        t.save()
        for i in range(0,10):
            p = Post()
            p.topic = t
            p.title = 'First post %s' % i
            p.content = 'Content of the first post'
            p.save()

        t = Topic()
        t.name = 'Python'
        t.save()
        for i in range(0,20):
            p = Post()
            p.topic = t
            p.title = 'Second post %s ' % i
            p.content = 'Content of the second post'
            p.save()
            for i in range(0,20):
                c = Comment()
                c.author = 'Jim Morrison'
                c.content = ' #%s Very nice article. Thank you very much!!!' % i
                c.post = p
                c.save()

        
        print 'done'
开发者ID:zdimon,项目名称:angular,代码行数:35,代码来源:blog_load_data.py

示例3: post

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [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)
开发者ID:DheerendraRathor,项目名称:idc,代码行数:13,代码来源:views.py

示例4: addComment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
def addComment(request, postId):
	print "Add comment url visited"
	if request.method == 'POST':
		print "Post request received"
		form = CommentForm(request.POST)
		if form.is_valid():
			newComment = Comment()
			newComment.post = Blog.objects.get(id=postId)		
			newComment.body = form.cleaned_data['body']
			newComment.created_by = form.cleaned_data['created_by']
			newComment.save()
			print "Comment saved"
		else:
			print form.errors
	return viewPost(request, postId)
开发者ID:dmattia,项目名称:ethics-blog,代码行数:17,代码来源:views.py

示例5: test_create_comments

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
    def test_create_comments(self):
        p = self.create_post()

        l = []

        c = Comment()
        c.post = p
        c.cotent = "foo"
        c.rating = 9
        c.save()

        l.append(c)
        self.assertEquals(len(l), p.comments.count())

        c = Comment.objects.create(post=p, content="blah", rating=6)

        l.append(c)
        self.assertEquals(len(l), p.comments.count())
开发者ID:nonZero,项目名称:django-simple-example,代码行数:20,代码来源:tests.py

示例6: post_detail

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
def post_detail(request, post_id):
  context = RequestContext(request)
  if request.method == 'GET':
    try:
      post = Post.objects.get(pk=post_id)
    except Poll.DoesNotExist:
      raise Http404
    post_comment = Comment.objects.filter(post_id=post_id)
    return render_to_response('blog/post_detail.html', { 'post': post, 'post_comment': post_comment, 'post_id': post_id}, context)
  else:
    try:
      post = Post.objects.get(pk=post_id)
    except Poll.DoesNotExist:
      raise Http404
    comment = Comment()
    comment.content = request.POST['content']
    comment.user = request.user
    comment.post = post
    comment.save()
    return HttpResponseRedirect(reverse('post_detail', args=(post_id,)))
开发者ID:xwjiang,项目名称:myBlogSite,代码行数:22,代码来源:views.py

示例7: comment_create

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import post [as 别名]
def comment_create(request, post_slug):

    try:
        post = Post.objects.get(slug=post_slug)
    except Post.DoesNotExist:
        raise Http404()

    if "content_raw" not in request.POST:
        return redirect(
            reverse("blog:post_detail", args=[post.category.name, post_slug]))

    if not post.published and not request.user.is_superuser:
        raise PermissionDenied()

    comment = Comment()
    if request.user.is_authenticated():
        comment.user = request.user
    else:
        if ('user_name' not in request.POST or
                'user_email' not in request.POST):
            return redirect(
                reverse(
                    "blog:post_detail", args=[post.category.name, post_slug]))

        comment.user_name = request.POST['user_name']
        comment.user_email = request.POST['user_email']

    comment.content_raw = request.POST['content_raw']
    comment.post = post
    comment.save()

    send_email_notification.delay(
        title=u'Новый коментарии',
        message=u'Новый коменатрии \n{0}\n{1}'.format(
            reverse('blog:post_detail', args=[post.category.name, post_slug]),
            datetime.datetime.now()))

    return redirect(
        reverse("blog:post_detail", args=[post.category.name, post_slug]))
开发者ID:ilnurgi,项目名称:website,代码行数:41,代码来源:views.py


注:本文中的blog.models.Comment.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。