本文整理汇总了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)