Closed boosh closed 9 months ago
If you only require siblings you can query the children of the node's parent like so: node.parent.children.all()
No special method is required for this.
That doesn't work for top-level nodes with no parent.
Yeah, that's true. You can .filter(parent=None)
though. Here's almost an one-liner:
def get_siblings_of(node):
return Node.objects.filter(parent=node)
django-tree-queries doesn't need to add anything like this because you can achieve the same thing by using only Django's own functionality.
OK thanks. I think actually it's highlighted a bug in my code though. All trees should have root nodes :-).
Do I need to manually query where tree_depth is the same as the node I want siblings for or is there a helper method to retrieve a node's siblings I haven't found? It's not clear from the docs. Thanks