Django application for creating the tree structure in the model (very fast structure).
To create a new item in the tree need only choose a parent. The key (id) for the new item will be calculated automatically. You can get a list of the parents and the range of children without a database query.
Implemented to create a new item, delete the item, transfer item to the other parent (and the transfer of the group).
This app is available on PyPI.
Supports Django 1.8 and later on Python 2.7, 3.2 - 3.5.
Works only with PostgreSQL 9.1 and later!
Clone this repository. The is an example of a project (app
Change the settings for connecting to the correct PostgreSQL DB.
pip install django-treensl
- Add app
- Create a new class of models from
treensl.models). Add your field in the model (for their fields, do not use the following names:
holes). If necessary, change the dimension of the default tree (properties
CHILDREN). For example see myapp/models.py
python manage.py makemigrations
- The new file migration, add the 3 lines as in the example file myapp/migrations/0001_initial.py (the rows are marked with comments
# add after makemigrations)
Possible dimensions of the tree
Before executing the
migrate you can adjust the settings tree. The dimension of the tree depends on the length
Recommended values (in the format
- For int32:
- For int64:
python manage.py migrate
Now, to create a new item in the tree need only choose a parent. The key (id) for the new item will be calculated automatically.
You can get a list of the parents and the range of children without a database query.
id call functions from the treensl.calc_values:
parents_list(id, LEVELS, CHILDREN, ROOT_ID)- returns a list of the first to the last parent
children_range(id, LEVELS, CHILDREN, ROOT_ID)- returns a list of the range of children
ROOT_ID - settings current tree