当前位置: 首页>>代码示例>>Python>>正文


Python Category.select方法代码示例

本文整理汇总了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"}
开发者ID:wdvill,项目名称:cloud_admin,代码行数:38,代码来源:user.py

示例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))
开发者ID:hooops,项目名称:PersonalWebsite,代码行数:8,代码来源:blog.py

示例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)
开发者ID:hooops,项目名称:PersonalWebsite,代码行数:5,代码来源:blog.py

示例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]'
开发者ID:eregnier,项目名称:checkme,代码行数:27,代码来源:manage.py


注:本文中的models.category.Category.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。