本文整理汇总了Python中models.Post.category方法的典型用法代码示例。如果您正苦于以下问题:Python Post.category方法的具体用法?Python Post.category怎么用?Python Post.category使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.category方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_to_entity
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import category [as 别名]
def convert_to_entity(json):
if json['status'] != "publish" or json['slug'] == 'placeholder':
return None
post = Post(key=get_key(json['slug']))
post.title = json['title']
post.content = json['content'].replace("\n", "")
date = json['modified']
post.time_added = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
if len(json['categories']) > 0:
category = json['categories'][0]
if category['parent'] != 8:
return None
key = categories.get_key(category['slug'])
post.category = key
else:
return None
date = json['date']
post.date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
return post
示例2: save
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import category [as 别名]
def save(cls, request: Request, *args, **kwargs):
""" Метод для сохранения поста
:param request:
:param kwargs:
:return:
"""
if request.get("id", False):
post = blog.get_post(request.get("id"))
else:
post = Post()
post.title = request.get("title")
post.short = request.get("short")
post.imgs = request.get("imgs", [])
post.body = request.get("body", "")
post.tags = request.get("tags", [])
post.category = request.get("category", None)
post.draft = request.get("draft", True)
post.author_id = request.get("author_id", False)
post.author_name = request.get("author_name", False)
post.source = request.get("source", False)
return {"post_id": post.save()}
示例3: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import category [as 别名]
def post(self, title):
if self.form.validate():
post = None
if self.form.post_id.data:
post = yield Post.asyncQuery(id=self.form.post_id.data).first()
if post:
post.modified_time = datetime.datetime.utcnow()
else:
post = Post()
post.create_time = \
self.BeiJing2UTCTime(self.form.create_time.data)
title = self.form.title.data.replace(' ', '-')
content = self.form.content.data
markdown_text = self.form.markdown.data
tags = self.separate_tags(self.form.tags.data)
category_str = self.form.category.data.capitalize()
category = yield Category.asyncQuery(
name=category_str).first()
if not category:
category = Category()
category.name = category_str
yield category.save()
post.title = title
post.content = content
post.markdown = markdown_text
post.category = category
post.tags = tags
post.author = self.current_user
yield post.save()
self.flash("compose finsh!")
return self.redirect('/blog')
self.render("compose.html", form=self.form)