From dbe86fe2a70dd1e254d7a6355eab4774ac520a68 Mon Sep 17 00:00:00 2001 From: Svintsov Dmitry Date: Fri, 22 Jun 2018 12:07:34 +0500 Subject: [PATCH] fix rebuild tree --- docs/initialize.rst | 5 ++++- sqlalchemy_mptt/tests/test_events.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/initialize.rst b/docs/initialize.rst index 6c75200..df1e513 100644 --- a/docs/initialize.rst +++ b/docs/initialize.rst @@ -97,13 +97,16 @@ this: # Fill tree for item in items: + item.left = 0 + item.right = 0 + item.tree_id = 'my_tree_1' db.session.add(item) db.session.commit() ... tree_manager.register_events() # enabled MPTT events back - models.MyModelTree.rebuild_tree(db.session, models.MyModelTree.tree_id) # rebuild lft, rgt value automatically + models.MyModelTree.rebuild_tree(db.session, 'my_tree_1') # rebuild lft, rgt value automatically After an initial table with tree you can use mptt features. diff --git a/sqlalchemy_mptt/tests/test_events.py b/sqlalchemy_mptt/tests/test_events.py index 66c8931..e4bb734 100644 --- a/sqlalchemy_mptt/tests/test_events.py +++ b/sqlalchemy_mptt/tests/test_events.py @@ -191,9 +191,21 @@ def test_documented_initial_insert(self): tree_manager.register_events(remove=True) # Disable MPTT events + _tree_id = 'tree1' + for node_id, parent_id in [(1, None), (2, 1), (3, 1), (4, 2)]: - session.add(Tree(id=node_id, parent_id=parent_id)) + item = Tree( + id=node_id, + parent_id=parent_id, + left=0, + right=0, + tree_id=_tree_id + ) + session.add(item) session.commit() tree_manager.register_events() # enabled MPTT events back - Tree.rebuild_tree(session) # rebuild lft, rgt value automatically + Tree.rebuild_tree( + session, + _tree_id + ) # rebuild lft, rgt value automatically