本文整理汇总了Python中models.Post.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Post.by_id方法的具体用法?Python Post.by_id怎么用?Python Post.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import by_id [as 别名]
def get_post(post_id):
key = post_id
post, age = age_get(key)
if post is None:
post = Post.by_id(int(post_id))
age_set(key, post)
return post, age
示例2: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import by_id [as 别名]
def get(self, post_id):
post = Post.by_id(post_id)
if not post:
return self.error(404)
elif self.user.key().id() != post.author:
self.write("You don't have access to edit this post.")
else:
self.render('editpost.html', p=post)
示例3: test_add_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import by_id [as 别名]
def test_add_post(self):
from models import Post
with transaction.manager:
post = Post("Hallo World!", "Hallo body World!")
DBSession.add(post)
post = Post.by_id(1)
self.assertEqual(post.id, 1)
self.assertEqual("Hallo World!", post.title)
self.assertEqual("Hallo body World!", post.body)
示例4: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import by_id [as 别名]
def post(self, post_id):
post = Post.by_id(post_id)
if not post:
return self.error(404)
if self.user.key().id() != post.author:
message = 'You do not have access to delete this post.'
else:
post.delete()
message = 'This post has been deleted.'
self.write(json.dumps({'message': message}))