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


Python Post.category方法代码示例

本文整理汇总了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
开发者ID:aapteedea,项目名称:shiloh-ranch,代码行数:21,代码来源:posts.py

示例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()}
开发者ID:ayurjev,项目名称:z9blog-api,代码行数:23,代码来源:controllers.py

示例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)
开发者ID:chinakyc,项目名称:blog,代码行数:38,代码来源:blog.py


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