當前位置: 首頁>>代碼示例>>Python>>正文


Python TreeItem.parent方法代碼示例

本文整理匯總了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
開發者ID:hajime-nishida,項目名稱:django-sitetree,代碼行數:33,代碼來源:test_models.py

示例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)
開發者ID:elpaquete,項目名稱:django-sitetree,代碼行數:14,代碼來源:tests.py

示例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)
開發者ID:,項目名稱:,代碼行數:19,代碼來源:


注:本文中的sitetree.models.TreeItem.parent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。