Dynamic trees & Trees in apps¶
SiteTree allows you to define sitetrees within your apps.
Define a sitetree¶
Let's suppose you have books application and want to define a sitetree for it.
-
First create
sitetrees.pyin the directory ofbooksapp. -
Then define a sitetree with the help of
treeanditemfunctions fromsitetree.utilsmodule and assign it tositetreesmodule attribute
Please see tree and item signatures for possible options.
Note
If you added extra fields to the Tree and TreeItem models,
then you can specify their values when instantiating item see sections on custom models.
Export sitetree to DB¶
Now when your app has a defined sitetree you can use sitetree_resync_apps management command
to instantly move sitetrees from every (or certain) applications into DB:
Or solely for books application:
Dynamic trees¶
Optionally you can structure app-defined sitetrees into existing or new trees runtime.
Basically one should compose a dynamic tree with compose_dynamic_tree() and register it with register_dynamic_trees().
Let's suppose the following code somewhere where app registry is already created, e.g. config.ready() or even
in urls.py of your project.
Note
If you use only dynamic trees you can set SITETREE_DYNAMIC_ONLY = True to prevent the application
from querying trees and items stored in DB.
Access check¶
For dynamic trees you can implement access on per tree item basis.
Pass an access checking function in access_check argument.
Note
This function must accept tree argument and support pickling (e.g. be exposed on a module level).