Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better initialization of empty tree #54

Open
dshlai opened this issue Mar 30, 2017 · 0 comments
Open

better initialization of empty tree #54

dshlai opened this issue Mar 30, 2017 · 0 comments

Comments

@dshlai
Copy link

dshlai commented Mar 30, 2017

Hi!

In order to initialize an empty tree. I used the following code based on the example in the doc:

    # if the table is empty
    if not current_session.query(TreeDelcaretiveClass).all():
        tree_manager.register_events(remove=True)
        # Hard code the tree_id since I know this is the first node and the only root node in the current tree
        root = TreeDelcaretiveClass(name="Root", tree_id=1)
        # Hard code the left since I know the initial value for the left must be 1
        root.left = 1
        # Hard code the right since I know the initial value for the right must be 2
        root.right = 2
        current_session.add(root)
        current_session.commit()

        tree_manager.register_events()
        TreeDeclaretiveClass.rebuild_tree(current_session, TreeDeclaretive.tree_id)

Maybe this can be a function in the mixin module that help user initialize the empty tree?
With at least one item in the tree (even if it is not used), tree will be very easy to use afterward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant