本文整理匯總了Python中models.Category.asyncQuery方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.asyncQuery方法的具體用法?Python Category.asyncQuery怎麽用?Python Category.asyncQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Category
的用法示例。
在下文中一共展示了Category.asyncQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import asyncQuery [as 別名]
def get(self, category, page):
if not page:
page = 1
if not category:
category = "All"
if category.upper() == "ALL":
posts = yield Post.asyncQuery().order_by("-create_time").paginate(
page=int(page), per_page=self.settings['per_page'])
else:
c = yield Category.asyncQuery(name=category).first()
if not c:
raise tornado.web.HTTPError(404)
posts = yield Post.asyncQuery(
category=c).order_by("-create_time").paginate(
page=int(page), per_page=self.settings['per_page'])
categorys = yield Category.asyncQuery()
self.render("blog.html",
posts=posts,
categorys=categorys,
current_category=category)
示例2: post
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import asyncQuery [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)