Node
A single internal node in the tree graph. A Node should be viewed as a connection (the root) with the children being either leaf nodes or other Node instances.
Attributes
| Attribute | Type | Description |
|---|---|---|
| default | string = DEFAULT | Standard connector type. Clients usually won't use this at all and subclasses will usually override the value. |
| children | list = [] | A list of leaf nodes or other Node instances that represent the branches of the current tree graph. |
| connector | string = DEFAULT | The logical operator or connection type used to join the children of this node. |
| negated | boolean = false | A boolean flag indicating whether the sense of the root connector is inverted. |
| copy | callable | A reference to the copy method used to create a shallow copy of the Node instance. |
Constructor
Signature
def Node(
children: list = None,
connector: str = None,
negated: bool = False
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| children | list = None | A list of child nodes to be associated with this node. |
| connector | str = None | The connector type for the node; defaults to the class 'default' value if not provided. |
| negated | bool = False | A boolean flag indicating whether the node's logic is negated. |
Methods
create()
@classmethod
def create(
children: list = None,
connector: str = None,
negated: bool = False
) - > [Node](node.md?sid=django_utils_tree_node)
Create a new instance using Node() instead of init() as some subclasses, e.g. django.db.models.query_utils.Q, may implement a custom init() with a signature that conflicts with the one defined in Node.init().
Parameters
| Name | Type | Description |
|---|---|---|
| children | list = None | A list of leaf nodes or other Node instances to be added as children |
| connector | str = None | The logical connector string used to join children; defaults to the class's default connector |
| negated | bool = False | A flag indicating whether the sense of the root connector is inverted |
Returns
| Type | Description |
|---|---|
[Node](node.md?sid=django_utils_tree_node) | A new instance of the class or subclass with the specified properties |
add()
@classmethod
def add(
data: object,
conn_type: str
) - > object
Combine this tree and the data represented by data using the connector conn_type. The combine is done by squashing the node other away if possible.
Parameters
| Name | Type | Description |
|---|---|---|
| data | object | The new data or Node instance to be merged into the current tree |
| conn_type | str | The connector type to use for the combination; may trigger a tree restructuring if it differs from the current connector |
Returns
| Type | Description |
|---|---|
object | A node which can be used in place of data regardless if the node other got squashed or not |
negate()
@classmethod
def negate()
Negate the sense of the root connector.