A Django library for representing hierarchical data (tree structures) using a materialized path approach. Version 1.0.0, low release cadence (last updated 2021).
pip install django-modeltreeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Define a tree model by inheriting from ModelTree, then use create() with parent= for hierarchy.
Ensure custom save() calls super().save() to maintain path integrity.
Use get_tree() to get hierarchical structure.
Increase path_max_length in Meta if deep trees exceed default.
Override delete() or use .delete(keep_children=True) if partial removal needed.
Run python manage.py makemigrations and migrate after adding ModelTree subclass.
Use TreeForeignKey (from modeltree import TreeForeignKey) for the parent field.
Set path_max_length to a value <= 255 in Meta, or use a CharField path explicitly.