Node¶
Manager/QuerySet Methods¶
Methods used for building/manipulating¶
None
Methods returning a QuerySet of Nodes¶
- roots(node=None)¶
Returns a QuerySet of all root Nodes (nodes with no parents) in the Node model.
- Parameters
node (Node) – (optional) if specified, returns only the roots for that node
- Returns
Root Nodes
- Return type
QuerySet
- leaves(node=None)¶
Returns a QuerySet of all leaf Nodes (nodes with no children) in the Node model.
- Parameters
node (Node) – (optional) if specified, returns only the leaves for that node
- Returns
Leaf Nodes
- Return type
QuerySet
- islands()¶
Returns a QuerySet of all Nodes with no parents or children (degree 0).
- Returns
Island Nodes
- Return type
QuerySet
Methods returning a QuerySet of Edges¶
None
Methods returning a Boolean¶
None
Methods returning other values¶
None
Model Methods¶
Methods used for building/manipulating an instance¶
- add_child(child)¶
Provided with a Node instance, attaches that instance as a child to the current Node instance.
- Parameters
child (Node) – The Node to be added as a child
- Returns
The newly created Edge between self and child
- Return type
Edge
- add_children(children)¶
Provided with a QuerySet of Node instances, attaches those instances as children of the current Node instance.
- Parameters
children (QuerySet) – The Nodes to be added as children
- Returns
The newly created Edges between self and children
- Return type
list
- add_parent(parent)¶
Provided with a Node instance, attaches that instance as a parent to the current Node instance.
- Parameters
parent (Node) – The Node to be added as a parent
- Returns
The newly created Edge between self and parent
- Return type
Edge
- add_parents(parents)¶
Provided with a QuerySet of Node instances, attaches those instances as parents of the current Node instance.
- Parameters
parents (QuerySet) – The Nodes to be added as parents
- Returns
The newly created Edges between self and parents
- Return type
list
- remove_child(child, delete_node=False)¶
Removes the edge connecting this node to child if a child Node instance is provided. Optionally deletes the child node as well.
- Parameters
child (Node) – The Node to be removed as a child
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
- remove_children(children)¶
Provided with a QuerySet of Node instances, removes those instances as children of the current Node instance.
- Parameters
children (QuerySet) – The Nodes to be removed as children
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
- remove_all_children(delete_node=False)¶
Removes all children of the current Node instance, optionally deleting self as well.
- Parameters
children (QuerySet) – The Nodes to be removed as children
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
- remove_parent(parent, delete_node=False)¶
Removes the edge connecting this node to parent if a parent Node instance is provided. Optionally deletes the parent node as well.
- Parameters
parent (Node) – The Node to be removed as a parent
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
- remove_parents(parents)¶
Provided with a QuerySet of Node instances, removes those instances as parents of the current Node instance.
- Parameters
parents (QuerySet) – The Nodes to be removed as parents
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
- remove_all_parents(delete_node=False)¶
Removes all parents of the current Node instance, optionally deleting self as well.
- Parameters
parents (QuerySet) – The Nodes to be removed as parents
- Returns
True if any Nodes were removed, otherwise False
- Return type
bool
Methods returning a QuerySet of Nodes¶
- ancestors()¶
Returns all Nodes in connected paths in a rootward direction.
- Returns
Nodes
- Return type
QuerySet
- self_and_ancestors()¶
Returns all Nodes in connected paths in a rootward direction, prepending self.
- Returns
Nodes
- Return type
QuerySet
- ancestors_and_self()¶
Returns all Nodes in connected paths in a rootward direction, appending self.
- Returns
Nodes
- Return type
QuerySet
- descendants()¶
Returns all Nodes in connected paths in a leafward direction.
- Returns
Nodes
- Return type
QuerySet
- self_and_descendants()¶
Returns all Nodes in connected paths in a leafward direction, prepending self.
- Returns
Nodes
- Return type
QuerySet
- descendants_and_self()¶
Returns all Nodes in connected paths in a leafward direction, appending self.
- Returns
Nodes
- Return type
QuerySet
- siblings()¶
Returns all Nodes that share a parent with this Node.
- Returns
Nodes
- Return type
QuerySet
- self_and_siblings()¶
Returns all Nodes that share a parent with this Node, prepending self.
- Returns
Nodes
- Return type
QuerySet
- siblings_and_self()¶
Returns all Nodes that share a parent with this Node, appending self.
- Returns
Nodes
- Return type
QuerySet
- partners()¶
Returns all Nodes that share a child with this Node.
- Returns
Nodes
- Return type
QuerySet
- self_and_partners()¶
Returns all Nodes that share a child with this Node, prepending self.
- Returns
Nodes
- Return type
QuerySet
- partners_and_self()¶
Returns all Nodes that share a child with this Node, appending self.
- Returns
Nodes
- Return type
QuerySet
- clan()¶
Returns a QuerySet with all ancestor Nodes, self, and all descendant Nodes.
- Returns
Nodes
- Return type
QuerySet
- connected_graph()¶
Returns all nodes connected in any way to the current Node instance.
- Parameters
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Returns
Nodes
- Return type
QuerySet
- shortest_path(target_node)¶
Returns the shortest path from self to target Node. Resulting Queryset is sorted leafward, regardless of the relative position of starting and ending nodes.
- Parameters
target_node (Node) – The target Node for searching
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Returns
Nodes
- Return type
QuerySet
- all_paths(target_node)¶
Returns all paths from self to target Node. Resulting Queryset is sorted leafward, regardless of the relative position of starting and ending nodes.
- Parameters
target_node (Node) – The target Node for searching
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Returns
Nodes
- Return type
QuerySet
- roots()¶
Returns a QuerySet of all root Nodes, if any, for the current Node.
- Returns
Root Nodes
- Return type
QuerySet
- leaves()¶
Returns a QuerySet of all leaf Nodes, if any, for the current Node.
- Returns
Leaf Nodes
- Return type
QuerySet
For future consideration:
immediate_family (parents, self and children)
piblings (aka: aunts/uncles)
niblings (aka: nieces/nephews)
cousins
Methods returning a QuerySet of Edges¶
- ancestor_edges()¶
Ancestor Edge instances for the current Node.
- Returns
Ancestor Edges
- Return type
QuerySet
- descendant_edges()¶
Descendant Edge instances for the current Node.
- Returns
Descendant Edges
- Return type
QuerySet
- clan_edges()¶
Clan Edge instances for the current Node.
- Returns
Clan Edges
- Return type
QuerySet
Methods returning a Boolean¶
- is_root()¶
Returns True if the current Node instance has no parents (Node has an in-degree 0 and out-degree >= 0).
- Return type
bool
- is_leaf()¶
Returns True if the current Node instance has no children (Node has an in-degree >=0 and out-degree 0).
- Return type
bool
- is_island()¶
Returns True if the current Node instance has no parents or children (Node has degree 0).
- Return type
bool
- path_exists_from(target_node, directional=True)¶
Checks whether there is a path from the target Node instance to the current Node instance.
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
- path_exists_to(target_node, directional=True)¶
Checks whether there is a path from the current Node instance to the target Node instance.
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
- is_ancestor_of(target_node, directional=True)¶
Checks whether the current Node instance is an ancestor of the provided target Node instance.
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
- is_descendant_of(target_node, directional=True)¶
Checks whether the current Node instance is a descendant of the provided target Node instance.
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
- is_sibling_of(target_node, directional=True)¶
Checks whether the current Node instance is a sibling of the provided target Node instance (see terminology).
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
- is_partner_of(target_node, directional=True)¶
Checks whether the current Node instance is a partner of the provided target Node instance (see terminology).
- Parameters
target_node (Node) – The node to compare against
directional (Node) – (optional) if True, path searching operates normally (in leafward direction), if False search operates in both directions
- Return type
bool
Methods returning other values¶
- ancestor_count()¶
Returns the total number of ancestor Nodes.
- Return type
int
- descendant_count()¶
Returns the total number of descendant Nodes.
- Return type
int
- clan_count()¶
Returns the total number of clan Nodes.
- Return type
int
- sibling_count()¶
Returns the total number of sibling Nodes.
- Return type
int
- partner_count()¶
Returns the total number of partner Nodes.
- Return type
int
- connected_graph_node_count()¶
Returns the count of all ancestors Nodes, self, and all descendant Nodes.
- Return type
int
- node_depth()¶
Returns the depth of this Node instance from furthest root Node.
- Return type
int
- distance(target_node)¶
Returns the shortest hops count to the target Node.
- Parameters
target_node (Node) – The node to compare against
- Return type
int
For future consideration:
descendant_tree()
ancestor_tree()
- graphs()¶
A Node can be associated with multiple Graphs. This method returns a QuerySet of all Graph instances associated with the current Node.
- Returns
Graphs to which this Node belongs
- Return type
QuerySet