本文整理汇总了Python中models.Category.findNumber方法的典型用法代码示例。如果您正苦于以下问题:Python Category.findNumber方法的具体用法?Python Category.findNumber怎么用?Python Category.findNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.findNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: categorys_tag2bit
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findNumber [as 别名]
def categorys_tag2bit(categorys_tag):
'''
Convert categorys from tag to bit.
'''
categorys_bit = 0
for category_tag in categorys_tag:
if category_tag["category_checked"] == True:
status = yield from Category.findNumber('count(id)', 'name="%s" and id="%s"' % (category_tag["category_name"], category_tag["category_id"]))
# verify the status of category record.
if 1 == status:
categorys_bit += (1 << int(category_tag["category_id"]))
return categorys_bit
示例2: api_update_categroy
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findNumber [as 别名]
def api_update_categroy(request, *, id, name, weight):
check_admin(request)
if not name or not name.strip():
raise APIValueError("name", "错误:类别名不应为空,请填写类别名。")
if not weight:
raise APIValueError("weight", "错误:类别权重区间为1~100,请设置正确的值。")
if int(weight) < 1 or int(weight) > 100:
raise APIValueError("weight", "错误:类别权重区间为1~100,请设置正确的值。")
sameName = yield from Category.findNumber('count(id)', 'name="%s" and id!="%s"' % (name, id))
if not 0 == sameName:
raise APIValueError("name", "错误:已存在同名类别,请使用其他类别名。")
category = Category(id=id, name=name, weight=weight)
yield from category.update()
return category
示例3: api_add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import findNumber [as 别名]
def api_add_category(request, *, nameAdded, weightAdded):
check_admin(request)
if not nameAdded or not nameAdded.strip():
raise APIValueError("name", "错误:类别名不应为空,请填写类别名。")
if not weightAdded:
raise APIValueError("weight", "错误:类别权重区间为1~100,请设置正确的值。")
if int(weightAdded) < 1 or int(weightAdded) > 100:
raise APIValueError("weight", "错误:类别权重区间为1~100,请设置正确的值。")
sameName = yield from Category.findNumber('count(id)', 'name="%s"' % nameAdded)
if not 0 == sameName:
raise APIValueError("name", "错误:已存在同名类别,请使用其他类别名。")
idAdded = 64
for i in range(64):
matchItem = yield from Category.find(i)
if None == matchItem:
idAdded = i
break
if idAdded == 64:
raise APIValueError("name", "错误:最多支持64个分类,资源不足。")
category = Category(id=idAdded, name=nameAdded, weight=weightAdded)
rows = yield from category.save()
if not rows == 1:
raise APIValueError("name", "错误:数据库操作失败。")
return category