本文整理汇总了Python中app.models.Category.select方法的典型用法代码示例。如果您正苦于以下问题:Python Category.select方法的具体用法?Python Category.select怎么用?Python Category.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_edit
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import select [as 别名]
def post_edit(post_id):
if request.method == 'GET':
try:
post = Post.get(Post.post_id == post_id) # todo: get not deleted
except Post.DoesNotExist:
abort(404)
form = PostForm(obj=post)
all_categories = Category.select()
template = env.get_template('post/edit.html')
return template.render(
item=post,
form=form,
categories=all_categories,
)
elif request.method == 'POST':
post = Post.get(Post.post_id == post_id)
post.category = post_get('category-id')
post.post_text = post_get('text')
post.slug = post_get('slug')
post.title = post_get('title')
post.draft = bool(int(post_get('draft'))) # zero int is False
post.language = post_get('language')
post.show_on_index = bool(post_get('show-on-index'))
post.date_updated = datetime.now()
new_tags = post_get('tags')
old_tags = Tag.select().join(Tag_to_Post)\
.where(Tag_to_Post.post_id == post_id)
remove_tags(old_tags, new_tags, post_id)
add_new_tags(new_tags, post_id)
post.save()
app.flash('Article updated')
redirect('/post/' + str(post_id))
示例2: post_add
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import select [as 别名]
def post_add():
form = PostForm()
if request.method == 'GET':
all_categories = Category.select()
template = env.get_template('post/add.html')
return template.render(
form=form,
categories=all_categories,
)
if request.method == 'POST':
post = Post.create(
category=post_get('category-id'),
post_text=post_get('text'),
title=post_get('title'),
slug=post_get('slug'),
user=app.current_user.user_id,
date_posted=datetime.now(),
draft=bool(int(post_get('draft'))),
show_on_index=bool(post_get('show-on-index')),
language=post_get('language'),
)
post_id = post.post_id
post.save()
add_new_tags(post_get('tags'), post_id)
redirect('/post/' + str(post_id))
示例3: category_add
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import select [as 别名]
def category_add():
if request.method == 'GET':
all_categories = Category.select()
template = env.get_template('post/category_add.html')
return template.render(categories=all_categories)
if request.method == 'POST':
new_category = Category.create(category_name=post_get('category_name'))
app.flash(u'Нова категорія була успішно додана')
redirect('/category/add')