
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
django-materialized-paths
Advanced tools
A simple and lightweight implementation of materialized path tree structures in Django.
A simple and lightweight implementation of materialized path tree structures in Django.
To install, run:
pip install django-materialized-paths
Add the following into the INSTALLED_APPS of your projects:
INSTALLED_APPS = (
...
'django-materialized-paths',
)
To use, extend the BaseNode into your model:
from django-materialized-paths import BaseNode
class FolderExample(BaseNode):
"""My folder class"""
name = models.CharField(max_length=48)
The model overrides Django's django.db.models.Model save() method to automatically manage changes to inheritance:
from .models import FolderExample # concrete class from above
root = FolderExample.objects.create(name="root")
child = FolderExample.objects.create(name="child", parent=root)
grandchild = FolderExample.objects.create(name="child", parent=child)
For example, to convert grandchild to a root:
grandchild.parent = None
grandchild.save()
BaseNode.depth # Root is 0
BaseNode.parent
BaseNode.children # Only returns direct descendants
BaseNode.save() # Set the parent field to automatically manage hierarchy
BaseNode.delete() # NOTE: The BaseNode.parent field is set to cascade, so deleting a parent will delete all children
Note that these methods generally return querysets
# Accessors
BaseNode.get_root()
BaseNode.get_ancestor(depth=int)
BaseNode.get_ancestors()
BaseNode.get_descendants()
BaseNode.get_siblings()
# Convenience
BaseNode.has_children()
BaseNode.is_child_of(parent_id=int)
# ID-based accessors - computed directly from path without accessing db
BaseNode.get_ancestors_ids()
BaseNode.get_descendants_ids()
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
A simple and lightweight implementation of materialized path tree structures in Django.
We found that django-materialized-paths demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.