mirror of https://github.com/jumpserver/jumpserver
				
				
				
			[Update] 创建子节点支持id
							parent
							
								
									49404f763d
								
							
						
					
					
						commit
						c4af6fa72d
					
				| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue