feat(node): NodeModel添加方法get_or_create_child()

pull/4242/head
Bai 2020-07-02 18:49:17 +08:00
parent 8f347eee4d
commit 872e2546e9
1 changed files with 14 additions and 0 deletions

View File

@ -199,6 +199,20 @@ class FamilyMixin:
)
return child
def get_or_create_child(self, value, _id=None):
"""
:return: Node, bool (created)
"""
children = self.get_children()
exist = children.filter(value=value).exists()
if exist:
child = children.filter(value=value).first()
created = False
else:
child = self.create_child(value, _id)
created = True
return child, created
def get_next_child_key(self):
mark = self.child_mark
self.child_mark += 1