Utilities for implementing a modified pre-order traversal tree (nested sets) in django.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_mptt2-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 627c00fa7ee0a3210726d531b5b95932d4f99046c5258184c694fa48d39f580c |
|
MD5 | 7e40389f93e61a4c60588e73c3fd1800 |
|
BLAKE2b-256 | 2422b81986a2f36e92cc512bffeb8daf6c6a3403353d6aa5b25d35e6bb521627 |