1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
Nested Sets trees
=================
.. module:: treebeard.ns_tree
An implementation of Nested Sets trees for Django, 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.
.. warning::
As with all tree implementations, please be aware of the
:doc:`caveats`.
.. inheritance-diagram:: NS_Node
.. autoclass:: NS_Node
:show-inheritance:
.. warning::
If you need to define your own
:py:class:`~django.db.models.Manager` class,
you'll need to subclass
:py:class:`~NS_NodeManager`.
Also, if in your manager you need to change the default
queryset handler, you'll need to subclass
:py:class:`~NS_NodeQuerySet`.
.. attribute:: 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:
.. code-block:: python
node_order_by = ['field1', 'field2', 'field3']
.. attribute:: depth
``PositiveIntegerField``, depth of a node in the tree. A root node
has a depth of *1*.
.. attribute:: lft
``PositiveIntegerField``
.. attribute:: rgt
``PositiveIntegerField``
.. attribute:: tree_id
``PositiveIntegerField``
.. automethod:: get_tree
See: :meth:`treebeard.models.Node.get_tree`
.. note::
This method returns a queryset.
.. autoclass:: NS_NodeManager
:show-inheritance:
.. autoclass:: NS_NodeQuerySet
:show-inheritance:
.. _`Joe Celko`: http://en.wikipedia.org/wiki/Joe_Celko
.. _`Trees and Hierarchies in SQL for Smarties`:
https://shop.elsevier.com/books/joe-celkos-trees-and-hierarchies-in-sql-for-smarties/celko/978-0-12-387733-8
|