本文整理汇总了Python中app.models.Category.create方法的典型用法代码示例。如果您正苦于以下问题:Python Category.create方法的具体用法?Python Category.create怎么用?Python Category.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_init
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import create [as 别名]
def db_init():
"""Initialize the database."""
from app import db
db.create_all()
click.echo('Initialize the database.')
from app.models import Category
c1 = Category.create(name=u'Uncategorized', slug=u'uncategorized')
c1.save()
c2 = Category.create(name=u'News', slug=u'news')
c2.save()
示例2: post
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import create [as 别名]
def post(self):
form = CategoryForm()
if form.is_submitted():
try:
if not form.validate():
raise Exception(_('ERROR_INVALID_SUBMISSION'))
category = Category.create()
if not form.slug.data:
form.slug.data = form.name.data
form.slug.data = Category.urlify(form.slug.data)
form.populate_obj(category)
category.save()
return render_view(url_for('CategoriesView:put', id=category.id),
message=_('CATEGORY_CREATE_SUCESS'),
redirect=True)
except Exception as e:
flash(e.message, 'error')
return render_view('admin/categories/add.html', form=form)
示例3: category_add
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import create [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')
示例4: post
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import create [as 别名]
def post(self):
form = CategoryForm()
if request.method == "POST":
if form.validate_on_submit():
try:
category = Category.create()
form.populate_obj(category)
category.save()
flash(gettext("Category succesfully created"))
return util.redirect_json_or_html(url_for("CategoriesView:index"), "category")
except:
flash(gettext("Error while creating the category"), "error")
else:
flash(gettext("Invalid submission, please check the message below"), "error")
return render_template("admin/categories/add.html", title=gettext("Create Category"), form=form)