# django-treebeard

django-treebeard is a library that implements efficient tree implementations for the Django Web Framework 1.8+, written by Gustavo Picón and licensed under the Apache License 2.0.

`django-treebeard` is:

- Flexible: Includes 3 different tree implementations with the same API:

  1. Adjacency List

  2. Materialized Path

  3. Nested Sets

- Fast: Optimized non-naive tree operations

- Easy: Uses Django’s model-inheritance with abstract-base-classes. to define your own models.

- Clean: Testable and well tested code base. Code/branch test coverage is above 96%.

## Overview

- Installation
  - Prerequisites
  - Installing
    - pip (or easy_install)
    - setup.py
    - .deb packages
  - Configuration
- Tutorial
- Known Caveats
  - Raw Queries
  - Overriding the default manager
  - Custom Managers
  - Copying model instances

- Changelog

## Reference

- API
  - `Node`
    - `Node.add_root()`
    - `Node.add_child()`
    - `Node.add_sibling()`
    - `Node.delete()`
    - `Node.get_tree()`
    - `Node.get_depth()`
    - `Node.get_ancestors()`
    - `Node.get_children()`
    - `Node.get_children_count()`
    - `Node.get_descendants()`
    - `Node.get_descendant_count()`
    - `Node.get_first_child()`
    - `Node.get_last_child()`
    - `Node.get_first_sibling()`
    - `Node.get_last_sibling()`
    - `Node.get_prev_sibling()`
    - `Node.get_next_sibling()`
    - `Node.get_parent()`
    - `Node.get_root()`
    - `Node.get_siblings()`
    - `Node.is_child_of()`
    - `Node.is_descendant_of()`
    - `Node.is_sibling_of()`
    - `Node.is_root()`
    - `Node.is_leaf()`
    - `Node.move()`
    - `Node.save()`
    - `Node.get_first_root_node()`
    - `Node.get_last_root_node()`
    - `Node.get_root_nodes()`
    - `Node.load_bulk()`
    - `Node.dump_bulk()`
    - `Node.find_problems()`
    - `Node.fix_tree()`
    - `Node.get_descendants_group_count()`
    - `Node.get_annotated_list()`
    - `Node.get_annotated_list_qs()`
    - `Node.get_database_vendor()`
- Materialized Path trees
  - `MP_Node`
    - `MP_Node.steplen`
    - `MP_Node.alphabet`
    - `MP_Node.node_order_by`
    - `MP_Node.path`
    - `MP_Node.depth`
    - `MP_Node.numchild`
    - `MP_Node.add_root()`
    - `MP_Node.add_child()`
    - `MP_Node.add_sibling()`
    - `MP_Node.move()`
    - `MP_Node.get_tree()`
    - `MP_Node.find_problems()`
    - `MP_Node.fix_tree()`
  - `MP_NodeManager`
  - `MP_NodeQuerySet`
- Nested Sets trees
  - `NS_Node`
    - `NS_Node.node_order_by`
    - `NS_Node.depth`
    - `NS_Node.lft`
    - `NS_Node.rgt`
    - `NS_Node.tree_id`
    - `NS_Node.get_tree()`
  - `NS_NodeManager`
  - `NS_NodeQuerySet`
- Adjacency List trees
  - `AL_Node`
    - `AL_Node.node_order_by`
    - `AL_Node.parent`
    - `AL_Node.sib_order`
    - `AL_Node.get_depth()`
  - `AL_NodeManager`
- Exceptions
  - `InvalidPosition`
  - `InvalidMoveToDescendant`
  - `NodeAlreadySaved`
  - `PathOverflow`
  - `MissingNodeOrderBy`

## Additional features

- Admin
  - API
    - `TreeAdmin`
    - `admin_factory()`
  - Interface
    - Advanced Interface
    - Basic Interface
    - Model Detail Pages
- Forms
  - `MoveNodeForm`
  - `movenodeform_factory()`

## Development

- Running the Test Suite
  - pytest
  - tox

# Indices and tables

- Index

- Module Index

- Search Page