django-orderable-tree

Tree structure for hierarchical data


Keywords
tree, database, hierarchical
License
Other
Install
pip install django-orderable-tree==0.1.0

Documentation

Django Tree

CI Test Coverage Maintainability

Overview

A tree structure for hierarchical data. Optimised for fast insertion/moving of nodes around the tree.

Requirements

  • Django 3.2+
  • Python 3.8+

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

# Will contain an OrderedDict of categories organised into a tree structure.
categories = Category.objects.build_tree()

Testing

  1. Install dev dependencies: poetry install.
  2. Install a supported version of Django: pip install django==3.2
  3. Run the tests: DB_NAME="django_tree" python -m pytest tests .