本文整理汇总了Python中app.models.Category.check_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Category.check_by_name方法的具体用法?Python Category.check_by_name怎么用?Python Category.check_by_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.check_by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_category_to_article
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import check_by_name [as 别名]
def save_category_to_article():
category_name = request.form.get('categoryname')
category_description = request.form.get('categorydescription')
if(category_name != None and category_description != None and category_name !="" and category_description != ""):
category = Category.check_by_name(category_name)
if(category is None):
category = Category(name=category_name,description=category_description)
print("111")
try:
db.session.add(category)
db.session.commit()
except:
flash("save_category Database error!")
return json.dumps({"id":category.id,"categoryname":category.name,"categorydescription":category.description})
示例2: add_category
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import check_by_name [as 别名]
def add_category():
categoryform = CategoryForm()
if categoryform.validate_on_submit():
category_name = request.form.get('name')
category_description = request.form.get('description')
if(category_name != None and category_description != None and category_name !="" and category_description != ""):
category = Category.check_by_name(category_name)
if(category is None):
category = Category(name=category_name,description=category_description)
else:
flash("category:%s is already exit" % category)
try:
db.session.add(category)
db.session.commit()
except:
flash("add_category Database error!")
return render_template("admin/addcategory.html",categoryform=categoryform)
return redirect(url_for('list_category'))
return render_template("admin/addcategory.html",categoryform=categoryform)