A tree structure for hierarchical data. Optimised for fast insertion/moving of nodes around the tree.
- Django 3.2+
- Python 3.8+
- Add
django_tree
toINSTALLED_APPS
.
Simply extend the BaseTreeNode
class in your application: e.g.
from django.db import models
from django_tree.models import BaseTreeNode
class Category(BaseTreeNode):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
# Will contain an OrderedDict of categories organised into a tree structure.
categories = Category.objects.build_tree()
- Install dev dependencies:
poetry install
. - Install a supported version of Django:
pip install django==3.2
- Run the tests:
DB_NAME="django_tree" python -m pytest tests .