本文整理汇总了Python中sitetree.models.TreeItem.parent方法的典型用法代码示例。如果您正苦于以下问题:Python TreeItem.parent方法的具体用法?Python TreeItem.parent怎么用?Python TreeItem.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sitetree.models.TreeItem
的用法示例。
在下文中一共展示了TreeItem.parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_tree_item
# 需要导入模块: from sitetree.models import TreeItem [as 别名]
# 或者: from sitetree.models.TreeItem import parent [as 别名]
def test_model_tree_item():
from sitetree.models import Tree, TreeItem
tree1 = Tree(alias='test')
tree1.save()
item1 = TreeItem(tree=tree1, alias='only', title='only title')
item1.save()
assert str(item1) == item1.title
item2 = TreeItem(tree=tree1, alias='other', parent=item1)
item2.save()
item3 = TreeItem(tree=tree1, parent=item1)
item3.save()
item3.sort_order = 100
item3.parent = item3
item3.save()
assert item3.parent is None # Can't be itself
assert item3.sort_order == 100
item3.sort_order = 0
item3.save()
assert item3.sort_order == item3.id # Automatic ordering
with pytest.raises(Exception):
TreeItem(tree=tree1, alias='only').save() # Unique alias within tree
示例2: test_no_recursive_parents
# 需要导入模块: from sitetree.models import TreeItem [as 别名]
# 或者: from sitetree.models.TreeItem import parent [as 别名]
def test_no_recursive_parents(self):
"""Verify that treeitems cannot be their own parent."""
tree = Tree(alias="mytree")
tree.save()
tree_item = TreeItem(title="i'm my own grandpa", tree=tree)
# This item needs to be saved, otherwise it cannot be set
# as a parent.
tree_item.save()
tree_item.parent = tree_item
tree_item.save()
self.assertNotEqual(tree_item, tree_item.parent)
示例3: attach_items
# 需要导入模块: from sitetree.models import TreeItem [as 别名]
# 或者: from sitetree.models.TreeItem import parent [as 别名]
def attach_items(tree, items, parent=None):
for item_dict in items:
children = item_dict.pop('children', [])
access_permissions = item_dict.pop('access_permissions', [])
item = TreeItem(**item_dict)
item.tree = tree
item.parent = parent
item.save()
for permission in access_permissions:
item.access_permissions.add(Permission.objects.get(codename=permission))
items_map['%s' % item.url] = item
children and attach_items(tree, children, parent=item)