本文整理汇总了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)
示例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'
示例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)
示例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)
示例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())
示例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,)))
示例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]))