Welcome to django-mptt2 documentation!
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.
Contents
- Installation
- Tutorial
- Admin Sites
- Development
- Changelog
- Code documentation
Position
Tree
Node
Node.Meta
Node.delete()
Node.descendant_count
Node.get_ancestors()
Node.get_children()
Node.get_descendants()
Node.get_family()
Node.get_root()
Node.get_siblings()
Node.has_leafs
Node.insert_at()
Node.is_leaf_node
Node.is_root_node
Node.move_to()
Node.mptt_depth
Node.mptt_lft
Node.mptt_parent
Node.mptt_parent_id
Node.mptt_rgt
Node.mptt_tree
Node.mptt_tree_id
Node.objects
Node.subtree_width
TreeManager