Django Tree

Overview
A tree structure for hierarchical data. Optimised for fast insertion/moving of nodes around the tree.
Requirements
Installation
- Add
django_tree
to INSTALLED_APPS
.
Usage
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
categories = Category.objects.build_tree()
Testing
- 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 .