Skip to content

Commit c18ca54

Browse files
Implemented/added several more graph methods
1 parent bbf12ca commit c18ca54

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

django_postgresql_dag/models.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,36 @@ def is_island(self):
239239
"""
240240
return bool(not self.children.exists() and not self.parents.exists())
241241

242-
def is_descendant_of(self, target):
243-
# ToDo: Implement
244-
pass
242+
def is_ancestor_of(self, ending_node, **kwargs):
243+
try:
244+
return len(self.path_raw(ending_node, **kwargs)) >= 1
245+
except NodeNotReachableException:
246+
return False
247+
248+
def is_descendant_of(self, ending_node, **kwargs):
249+
return (
250+
not self.is_ancestor_of(ending_node, **kwargs)
251+
and len(self.path_raw(ending_node, directional=False, **kwargs)) >= 1
252+
)
245253

246-
def is_ancestor_of(self, target):
247-
# ToDo: Implement
248-
pass
254+
def is_sibling_of(self, ending_node):
255+
return ending_node in self.siblings()
249256

250-
def is_sibling_of(self, target):
251-
# ToDo: Implement
252-
pass
257+
def is_partner_of(self, ending_node):
258+
return ending_node in self.partners()
253259

254260
def node_depth(self):
255261
# Depth from furthest root
256262
# ToDo: Implement
257263
pass
258264

259-
def entire_graph(self):
265+
def connected_graph_raw(self, **kwargs):
260266
# Gets all nodes connected in any way to this node
261-
pass
267+
return ConnectedGraphQuery(instance=self, **kwargs).raw_queryset()
268+
269+
def connected_graph(self, **kwargs):
270+
pks = [item.pk for item in self.connected_graph_raw(**kwargs)]
271+
return self.ordered_queryset_from_pks(pks)
262272

263273
def descendants_tree(self):
264274
"""
@@ -364,6 +374,7 @@ def circular_checker(parent, child):
364374
return Node
365375

366376

377+
367378
class EdgeManager(models.Manager):
368379
def from_nodes_queryset(self, nodes_queryset):
369380
"""Provided a queryset of nodes, returns all edges where a parent and child

0 commit comments

Comments
 (0)