fromsitetree.modelsimportTreeItemBase,TreeBaseclassMyTree(TreeBase):"""This is your custom tree model. And here you add `my_tree_field` to all fields existing in `TreeBase`. """my_tree_field=models.CharField('My tree field',max_length=50,null=True,blank=True)classMyTreeItem(TreeItemBase):"""And that's a tree item model with additional `css_class` field."""css_class=models.CharField('Tree item CSS class',max_length=50)
Now when models.py in your myapp application has the definitions of custom sitetree models, you need
to instruct Django to use them for your project instead of built-in ones:
# Here `myapp` is the name of your application, `MyTree` and `MyTreeItem`# are the names of your customized models.SITETREE_MODEL_TREE='myapp.MyTree'SITETREE_MODEL_TREE_ITEM='myapp.MyTreeItem'
Run manage.py syncdb to install your customized models into DB.
Note
As you've added new fields to your models, you'll probably need to tune their Django Admin representation.
See section on custom Admin for more information.
fromsitetree.toolboximporttree,item# Be sure you defined `sitetrees` in your module.sitetrees=(# Define a tree with `tree` function.tree('books',items=[# Then define items and their children with `item` function.item('Books','books-listing',children=[item('Book named "{{ book.title }}"','books-details',in_menu=False,in_sitetree=False,css_class='book-detail'),item('Add a book','books-add',css_class='book-add'),item('Edit "{{ book.title }}"','books-edit',in_menu=False,in_sitetree=False,css_class='book-edit')])],title='My books tree'),# ... You can define more than one tree for your app.)
fromsitetree.settingsimportMODEL_TREE,MODEL_TREE_ITEM# As taken from the above given examples# MODEL_TREE will contain `myapp.MyTree`, MODEL_TREE_ITEM - `myapp.MyTreeItem`
If you need to get current tree or tree item classes use get_tree_model and get_tree_item_model functions:
fromsitetree.utilsimportget_tree_model,get_tree_item_modelcurrent_tree_class=get_tree_model()# MyTree from myapp.models (from the example above)current_tree_item_class=get_tree_item_model()# MyTreeItem from myapp.models (from the example above)