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.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

django_mptt2-0.2.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file django_mptt2-0.2.1.tar.gz.

File metadata

  • Download URL: django_mptt2-0.2.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_mptt2-0.2.1.tar.gz
Algorithm Hash digest
SHA256 54c3d829ec961d4c40bf2d2094225ac49cd22d1b1e52a28ada1492015b05b47b
MD5 1c6ed945f455cc973f751a0ef3518bac
BLAKE2b-256 4a4d06333583d8818e11948aa6170dcd44ce0292e4b2d02bb5c5b37d56bfa8e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_mptt2-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_mptt2-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47e85fccdc93f32b57c0aa30349a1ff68d1c1a6ae4cd08e1444108ccec696d7e
MD5 3e5d02724fd5e3e8ffc1b09e4bf49730
BLAKE2b-256 c2c045902ae3284b3cfa27611ad90ef5e3d5f61784ad67f85043f863b69adfca

See more details on using hashes here.

Supported by

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