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 Known Caveats.
treebeard.ns_tree.
NS_Node
(*args, **kwargs)¶
Bases: treebeard.models.Node
Abstract model to create your own Nested Sets Trees.
Warning
If you need to define your own Manager
class, you’ll need to subclass NS_NodeManager
.
Also, if in your manager you need to change the default queryset handler, you’ll need to subclass NS_NodeQuerySet
.
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
get_tree
(parent=None)¶
See: treebeard.models.Node.get_tree()
Note
This method returns a queryset.
treebeard.ns_tree.
NS_NodeManager
¶
Bases: django.db.models.manager.Manager
Custom manager for nodes in a Nested Sets tree.
treebeard.ns_tree.
NS_NodeQuerySet
(model=None, query=None, using=None, hints=None)¶
Bases: django.db.models.query.QuerySet
Custom queryset for the tree node manager.
Needed only for the customized delete method.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4