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


Python Category.add_root方法代码示例

本文整理汇总了Python中models.Category.add_root方法的典型用法代码示例。如果您正苦于以下问题:Python Category.add_root方法的具体用法?Python Category.add_root怎么用?Python Category.add_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Category的用法示例。


在下文中一共展示了Category.add_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_tree

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import add_root [as 别名]
def build_tree():
    """
    Builds the hierarchy tree for the CPVS. build_cpvs had to run before.

    Usage: from contracts.cpvs import build_tree; build_tree()
    """
    divisions = CPVS.divisions()

    get = lambda node_id: Category.objects.get(pk=node_id)

    for division in divisions:
        print ">      ", division.code
        div = Category.add_root(code=division.code,
                                description_en=division.description_en,
                                description_pt=division.description_pt)
        for group in division.groups():
            print ">>     ", group.code
            gro = get(div.id).add_child(code=group.code,
                                        description_en=group.description_en,
                                        description_pt=group.description_pt)
            for klass in group.classes():
                print ">>>    ", klass.code
                kla = get(gro.id).add_child(code=klass.code,
                                            description_en=klass.description_en,
                                            description_pt=klass.description_pt)
                for category in klass.categories():
                    print ">>>>   ", category.code
                    cat = get(kla.id).add_child(code=category.code,
                                                description_en=category.description_en,
                                                description_pt=category.description_pt)
                    for sub_category1 in category.sub_categories1():
                        print ">>>>>  ", sub_category1.code
                        sub = get(cat.id).add_child(code=sub_category1.code,
                                                    description_en=sub_category1.description_en,
                                                    description_pt=sub_category1.description_pt)
                        for sub_category2 in sub_category1.sub_categories2():
                            print ">>>>>> ", sub_category2.code
                            sub2 = get(sub.id).add_child(code=sub_category2.code,
                                                         description_en=sub_category2.description_en,
                                                         description_pt=sub_category2.description_pt)
                            for sub_category3 in sub_category2.sub_categories3():
                                print ">>>>>>>", sub_category3.code
                                get(sub2.id).add_child(code=sub_category3.code,
                                                       description_en=sub_category3.description_en,
                                                       description_pt=sub_category3.description_pt)
开发者ID:aorzh,项目名称:public-contracts,代码行数:47,代码来源:cpvs.py


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