Skip to main content

Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances.

Project description

Documentation Status PyPi version

django-mptt2

Based on the idea of the unmaintained django-mptt package i implemented this new code base to replace it.

Cause no other package fits all of my use cases, which are primary in fast reading tree’s from the database, i started working on this project.

There is an alternative to this package, called django-treebeard, which implements nested sets as well, but without a parent foreignkey.

Quick-Start

Install it as any other django app to your project:

$ pip install django-mptt2

Add django-mptt2 to INSTALLED_APPS:

INSTALLED_APPS = [
    # other apps
    "mptt2"
]

Inheritance from the abstract mptt2.models.Node Model:

from django.db import models
from mptt2.models import

class Genre(Node)
    name = models.CharField(max_length=50, unique=True)

Adding nodes:

from project.models import Genre

rock = Genre(name="Rock")
rock.insert_at() # it will become the root node without target parameter

metal = Genre(name="Metal")
metal.insert_at(target=rock) # it will become the last child from rock

alternative = Genre(name="Alternative")
alternative.insert_at(target=rock) # it will become the last child from rock, the right sibling of metal

For full usage description, please read the tutorial section of our documentation.

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-mptt2-0.2.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

django_mptt2-0.2.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file django-mptt2-0.2.0.tar.gz.

File metadata

  • Download URL: django-mptt2-0.2.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for django-mptt2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d1c290b1ab3dc1db3d42383b36459aba5ef3bbb461716a0a46fcb3f5a48d8a2c
MD5 b3a6a81b8a995886d6a7d0cc69f3074d
BLAKE2b-256 ea526e9ec781f54cf49698348f2551dbc49aabe68fdd2b078daed652e2757b6b

See more details on using hashes here.

File details

Details for the file django_mptt2-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_mptt2-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for django_mptt2-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c82d41f3b2a76fe74df95ff96ed6815f645164f645c2fb81707907d57d9fc417
MD5 72a9404b1dac97efe1224b64631bd912
BLAKE2b-256 06b3cc67ab306597dc3c6b2c114db9e1b8d72f579cd58012d5a3133e88822331

See more details on using hashes here.

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