本文整理汇总了Python中models.Post.id方法的典型用法代码示例。如果您正苦于以下问题:Python Post.id方法的具体用法?Python Post.id怎么用?Python Post.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import id [as 别名]
def update_post(filename, post_base_dir='./post/'):
filename = post_base_dir + filename
with open(filename) as f:
txt = f.readlines()
category = map(strip, txt[0].strip().split(','))
title = txt[1].strip()
tags = map(strip, txt[2].strip().split(','))
content = ''.join(txt[3:])
postid = get_postid(filename)
print 'postid...', postid
if not postid:
key = Post(category=category,
title=title,
tags=tags,
content=content).put()
print 'key...', key.id()
set_postid(filename, key.id())
print 'New post saved'
else:
post = Post.get_by_id(int(postid))
suggest = post.suggest
print suggest
post.category = category
post.title = title
post.tags = tags
post.content = content
post.suggest = suggest
post.put()
print 'Existed post saved'
示例2: create_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import id [as 别名]
def create_post():
"""Creates a new post with a new id"""
if not request.json:
abort(400)
form = PostEditForm.from_json(request.json, skip_unkown_keys=False)
if form.validate():
post = Post(json=form.data)
objId = mongo.db.posts.insert(post.to_bson())
post.id = str(objId)
return jsonify(**post.to_dict()), 201
else:
abort(400)
示例3: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import id [as 别名]
def get(self):
p_key = Post(title='title', content='content').put()
self.redirect('/bacheca/admin/edit/%s' % p_key.id())