本文整理匯總了Python中models.category.Category.select方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.select方法的具體用法?Python Category.select怎麽用?Python Category.select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.category.Category
的用法示例。
在下文中一共展示了Category.select方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: category_update
# 需要導入模塊: from models.category import Category [as 別名]
# 或者: from models.category.Category import select [as 別名]
def category_update(user, params):
# category example: 1,2,3,4,5
category = params.get('category')
try:
category_list = set(category.split(","))
except:
return {"error_code":20101, "msg":"category invalid"}
if len(category_list) != len(filter(utils.safe_id, category_list)):
return {"error_code":20103, "msg":"category invalid"}
if len(category_list) == 0:
return {"error_code":20102, "msg":"category not empty"}
cates = Category.select(Category.id)
cates = set([str(x.id) for x in cates])
if not category_list <= cates:
return {"error_code":20104, "msg":"category error"}
if len(category_list) > 10:
return {"error_code":20105, "msg":"category too large"}
exist_list = UserCategory.select(UserCategory.category).where(UserCategory.user == user)
exist_list = set([str(x.category_id) for x in exist_list])
if category_list == exist_list:
return {"error_code":0, "msg":"ok"}
new_cates = list(category_list.difference(exist_list))
del_cates = list(exist_list.difference(category_list))
for c in new_cates:
tmp_cate = UserCategory()
tmp_cate.user = user
tmp_cate.category = c
tmp_cate.save()
for d in del_cates:
UserCategory.delete().where(UserCategory.user == user, UserCategory.category == d).execute()
queue.to_queue({"type": "user_completeness", "user_id": user.id, "columns": ["category", ]})
return {"error_code":0, "msg":"ok"}
示例2: search_category
# 需要導入模塊: from models.category import Category [as 別名]
# 或者: from models.category.Category import select [as 別名]
def search_category(cls, search):
category_ids = cls.select(cls.category_id)
return Category.select(
Category.id,
Category.category
).filter(Category.id << category_ids).where(Category.category.contains(search))
示例3: get_all_category
# 需要導入模塊: from models.category import Category [as 別名]
# 或者: from models.category.Category import select [as 別名]
def get_all_category(cls):
category_ids = cls.select(cls.category_id)
return Category.select(Category.id, Category.category).filter(Category.id << category_ids)
示例4: get_database
# 需要導入模塊: from models.category import Category [as 別名]
# 或者: from models.category.Category import select [as 別名]
#! /usr/bin/python
# encoding: utf-8
from models.category import Category
from models.user import User
from models.check import Check
from models.base import get_database
import sys
if __name__ == '__main__':
if 'create' in sys.argv:
print 'Creating database... .'
db = get_database()
db.connect()
db.create_tables([User, Check, Category], safe=True)
print 'Creating database complete.'
elif 'fixtures' in sys.argv:
User.create('[email protected]', 'pass').save()
User.create('[email protected]', 'pass1').save()
elif 'count' in sys.argv:
print 'User', User.select().count()
print 'Category', Category.select().count()
print 'Check', Check.select().count()
else:
print 'Available actions are [create, fixtures, count]'