當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。