本文整理匯總了Python中models.Category.find方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.find方法的具體用法?Python Category.find怎麽用?Python Category.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Category
的用法示例。
在下文中一共展示了Category.find方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: api_add_category
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import find [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
示例2: api_delete_category
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import find [as 別名]
def api_delete_category(request, *, id):
check_admin(request)
category = yield from Category.find(id)
yield from category.remove()
return dict(id=id)