本文整理汇总了Python中model.Category.findOne方法的典型用法代码示例。如果您正苦于以下问题:Python Category.findOne方法的具体用法?Python Category.findOne怎么用?Python Category.findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Category
的用法示例。
在下文中一共展示了Category.findOne方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: category
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import findOne [as 别名]
def category(*, request, category_id):
# 获取当前分类的名字
category = yield from Category.findOne([category_id])
if category is not None:
# 获取博客分类和文章分类下的文章
category_sql = ['%s %s %s' % (
'select B.id,B.title,count(*) num from blog_category as A',
'left join category as B on A.category_id = B.id where B.is_delete = 0',
'group by A.category_id'
)]
blog_category = yield from select(category_sql, [])
# 获取热门文章
hot_blog_sql = ['select id,title,view_count from blogs order by view_count desc limit 10']
hot_blog = yield from select(hot_blog_sql, [])
return display('category', {'blog_category': blog_category, 'hot_blog': hot_blog, 'category': category})
else:
return redirect('/404')
示例2: edit_article
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import findOne [as 别名]
def edit_article(*, request, category_id):
cate = yield from Category.findOne(category_id)
if cate is not None:
return display('edit_category', {'cate': cate})
else:
return redirect('/404')