本文整理匯總了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