Registry / web-framework / django-treenode

django-treenode

JSON →
library0.24.0pypypiunverified

Probably the best abstract model/admin for your tree based stuff. Provides a Django model and admin mixin for managing tree structures using Materialized Path. Current version 0.24.0 supports Django 3.2–6.0 and Python 3.7–3.14. Released regularly, with recent versions adding Django 6.0 and Python 3.14 support.

pip install django-treenode
INSTALL
IMPORT
SIG · DJANGO-TREENODE
D
django-treenode
web-frameworkpythonv0.24.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.24.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TreeNodeModel
from treenode import TreeNodeModel
from treenode.models import TreeNodeModel

Define a tree model by subclassing TreeNodeModel and adding a tn_parent ForeignKey. The model automatically gets fields like tn_priority, tn_order, tn_level, tn_count, etc.

from django.db import models from treenode.models import TreeNodeModel class Category(TreeNodeModel): tn_parent = models.ForeignKey( 'self', on_delete=models.CASCADE, null=True, blank=True, related_name='children' ) name = models.CharField(max_length=255) def __str__(self): return self.name
Debug
Known issues
gotchaYou must define a ForeignKey named 'tn_parent' on your model. Using a different name will not be recognized.
fix
Add a ForeignKey to self with related_name='children' and null=True, blank=True, and name it exactly 'tn_parent'.
affects: all
gotchaCache must be configured for tree operations to work correctly. If not, tree methods may silently fail or log warnings.
fix
Ensure Django's cache framework is configured (e.g., CACHES setting). If you don't need caching, set a dummy cache.
affects: >=0.22.0
gotchaCircular references are now detected (since 0.23.3) but can still cause infinite recursion in older versions. Upgrade if you see recursion errors.
fix
Upgrade to 0.23.3 or later.
affects: <0.23.3
gotchaIn multi-database setups, write operations may not use the correct database. Fixed in 0.20.2.
fix
Upgrade to 0.20.2 or later.
affects: <0.20.2
Upgrade
Version history
0.24.0latest on PyPI · released Apr 15, 2026
Audit
Dependencies
Djangorequiredcore dependency
django-js-assetoptionalused for admin tree view assets
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
django-treenode — pip install django-treenode · libregistry