### Navigation

- index
- modules |
- next |
- previous |
- django-treebeard 2.0b1 documentation »

# Nested Sets trees

An implementation of Nested Sets trees for Django 1.4+, as described by Joe Celko in Trees and Hierarchies in SQL for Smarties.

Nested sets have very efficient reads at the cost of high maintenance on write/delete operations.

class `treebeard.ns_tree.``NS_Node`(*args, **kwargs)

  Bases: `treebeard.models.Node`

  Abstract model to create your own Nested Sets Trees.

  `node_order_by`

    Attribute: a list of model fields that will be used for node ordering. When enabled, all tree operations will assume this ordering.

    Example:

        node_order_by = ['field1', 'field2', 'field3']

  `depth`

    `PositiveIntegerField`, depth of a node in the tree. A root node has a depth of 1.

  `lft`

    `PositiveIntegerField`

  `rgt`

    `PositiveIntegerField`

  `tree_id`

    `PositiveIntegerField`

  classmethod `get_tree`(parent=None)

    Returns: |

    A queryset of nodes ordered as DFS, including the parent. If no parent is given, all trees are returned.

    See: `treebeard.Node.get_tree()`

    Note

    This metod returns a queryset.

### Navigation

- index
- modules |
- next |
- previous |
- django-treebeard 2.0b1 documentation »