Commit c4af6fa7 authored by ibuler's avatar ibuler

[Update] 创建子节点支持id

parent 49404f76
......@@ -163,12 +163,13 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
def create(self, request, *args, **kwargs):
instance = self.get_object()
value = request.data.get("value")
_id = request.data.get('id') or None
values = [child.value for child in instance.get_children()]
if value in values:
raise ValidationError(
'The same level node name cannot be the same'
)
node = instance.create_child(value=value)
node = instance.create_child(value=value, _id=_id)
return Response(self.serializer_class(instance=node).data, status=201)
def get_object(self):
......
......@@ -134,10 +134,10 @@ class Node(OrgModelMixin):
count = max(values) + 1 if values else 1
return '{} {}'.format(name, count)
def create_child(self, value):
def create_child(self, value, _id=None):
with transaction.atomic():
child_key = self.get_next_child_key()
child = self.__class__.objects.create(key=child_key, value=value)
child = self.__class__.objects.create(id=_id, key=child_key, value=value)
return child
def get_children(self, with_self=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment