Skip to content

Commit 22b5bef

Browse files
Made improvements to edge methods and stubbed out another node method
1 parent 6a55a71 commit 22b5bef

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

django_postgresql_dag/models.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ def ancestors_raw(self, max_depth=20, **kwargs):
337337
pass # Not implemented yet
338338

339339
NodeModel = self._meta.model
340-
print(ancestors_clauses_1)
341-
print(ancestors_clauses_2)
342340
raw_qs = NodeModel.objects.raw(
343341
ANCESTORS_QUERY.format(
344342
relationship_table=edge_model_table,
@@ -348,7 +346,6 @@ def ancestors_raw(self, max_depth=20, **kwargs):
348346
),
349347
query_parameters,
350348
)
351-
print(query_parameters)
352349
return raw_qs
353350

354351
def ancestors(self, **kwargs):
@@ -686,11 +683,16 @@ def is_sibling_of(self, target):
686683
# ToDo: Implement
687684
pass
688685

689-
def get_node_depth(self):
686+
def node_depth(self):
690687
# Depth from furthest root
691688
# ToDo: Implement
692689
pass
693690

691+
def entire_graph(self):
692+
# Gets all nodes connected in any way to this node
693+
694+
pass
695+
694696
def descendants_tree(self):
695697
"""
696698
Returns a tree-like structure with descendants
@@ -768,6 +770,14 @@ def circular_checker(parent, child):
768770

769771

770772
class EdgeManager(models.Manager):
773+
774+
def from_nodes_queryset(self, nodes_queryset):
775+
"""Provided a queryset of nodes, returns all edges where a parent and child
776+
node are within the queryset of nodes."""
777+
return _filter_order(
778+
self.model.objects, ["parent", "child"], nodes_queryset
779+
)
780+
771781
def descendants(self, node, **kwargs):
772782
"""
773783
Returns a queryset of all edges descended from the given node
@@ -788,19 +798,13 @@ def clan(self, node, **kwargs):
788798
"""
789799
Returns a queryset of all edges for ancestors, self, and descendants
790800
"""
791-
return _filter_order(
792-
self.model.objects, ["parent", "child"], node.clan(**kwargs)
793-
)
801+
return self.from_nodes_queryset(node.clan(**kwargs))
794802

795803
def path(self, start_node, end_node, **kwargs):
796804
"""
797805
Returns a queryset of all edges for the shortest path from start_node to end_node
798806
"""
799-
return _filter_order(
800-
self.model.objects,
801-
["parent", "child"],
802-
start_node.path(end_node, **kwargs),
803-
)
807+
return self.from_nodes_queryset(start_node.path(end_node, **kwargs))
804808

805809
def validate_route(self, edges, **kwargs):
806810
"""

0 commit comments

Comments
 (0)