Skip to main content

Adds hierarchical models to Django

Project description

django-hierarchical-models

This package provides several implementations Django models which support hierarchical data. Efficiently modeling hierarchical, or tree like data, in a relational database can be non-trivial. The following models implement the same interface, but there have different tradeoffs.

models.HierarchicalModelInterface

This abstract model defines the shared functionality of all hierarchical models. Some models may implement additional methods which are cheap for their implementation.

models.AdjacencyListModel

This is the most trivial implementation, using a single _parent foreign key field. Edits are efficient in this model, but queries for children/parents can be very expensive.

models.PathEnumerationModel

This model uses a _ancestors json field to store the path to its root. This model has middle ground efficiency for edits and queries. NOTE: This model requires database features that are not available in Oracle or SQLite backends. An exception will be raised if you attempt to use this model with an unsupported backend.

models.NestedSetModel

This model uses _left and _right integer fields to determine which instances it is parent/child to. Queries can be very efficient in this model, but edits can be very expensive, possibly even requiring updates to _left and _right fields of ever model instance for a single edit.

models.Node

Calls to HierarchicalModel.children() return this type, which has instance and children members, with the children being additional instances of Node.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_hierarchical_models-1.0.2.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distribution

django_hierarchical_models-1.0.2-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page