Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances.
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54c3d829ec961d4c40bf2d2094225ac49cd22d1b1e52a28ada1492015b05b47b
|
|
| MD5 |
1c6ed945f455cc973f751a0ef3518bac
|
|
| BLAKE2b-256 |
4a4d06333583d8818e11948aa6170dcd44ce0292e4b2d02bb5c5b37d56bfa8e5
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47e85fccdc93f32b57c0aa30349a1ff68d1c1a6ae4cd08e1444108ccec696d7e
|
|
| MD5 |
3e5d02724fd5e3e8ffc1b09e4bf49730
|
|
| BLAKE2b-256 |
c2c045902ae3284b3cfa27611ad90ef5e3d5f61784ad67f85043f863b69adfca
|