@@ -24,12 +24,28 @@ Create model with MPTT mixin:
2424 return " <Node (%s )>" % self .id
2525
2626
27- It automatically registers events.
27+
28+ Session
29+ -------
30+
31+ For the automatic tree maintainance triggered after session flush to work
32+ correctly, wrap the Session factory with :mod: `sqlalchemy_mptt.mptt_sessionmaker `
33+
34+ .. code-block :: python
35+ :linenos:
36+
37+ from sqlalchemy import create_engine
38+ from sqlalchemy.orm import sessionmaker
39+ from sqlalchemy_mptt import mptt_sessionmaker
40+
41+ engine = create_engine(' ...' )
42+ Session = mptt_sessionmaker(sessionmaker(bind = engine))
43+
2844
2945 Events
3046------
3147
32- But you can do it manually:
48+ The tree manager automatically registers events. But you can do it manually:
3349
3450.. code-block :: python
3551
@@ -77,7 +93,6 @@ Represented data of tree like dict
7793 {' id' : ' 10' , ' parent_id' : ' 7' },
7894 {' id' : ' 11' , ' parent_id' : ' 10' },
7995 )
80-
8196 Initializing a tree with data
8297-----------------------------
8398
@@ -110,19 +125,3 @@ tree management and finally call manually a rebuild of the tree once at the end:
110125 models.MyModelTree.rebuild_tree(db.session, 'my_tree_1') # rebuild lft, rgt value automatically
111126
112127After an initial table with tree you can use mptt features.
113-
114- Session
115- -------
116-
117- For the automatic tree maintainance triggered after session flush to work
118- correctly, wrap the Session factory with :mod: `sqlalchemy_mptt.mptt_sessionmaker `
119-
120- .. code-block :: python
121- :linenos:
122-
123- from sqlalchemy import create_engine
124- from sqlalchemy.orm import sessionmaker
125- from sqlalchemy_mptt import mptt_sessionmaker
126-
127- engine = create_engine(' ...' )
128- Session = mptt_sessionmaker(sessionmaker(bind = engine))
0 commit comments