mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-28 08:06:27 +00:00
[Bugfix] 资产树节点,取消model value unique,并添加唯一性校验,修改新增节点计数器规则
This commit is contained in:
@@ -51,6 +51,15 @@ class NodeSerializer(serializers.ModelSerializer):
|
||||
fields = ['id', 'key', 'value', 'parent', 'assets_amount', 'is_node']
|
||||
list_serializer_class = BulkListSerializer
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
value = validated_data.get('value')
|
||||
if not instance.is_root():
|
||||
children = instance.parent.get_children().exclude(key=instance.key)
|
||||
values = [child.value for child in children]
|
||||
if value in values:
|
||||
raise AssertionError('The same level node name cannot be the same')
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
@staticmethod
|
||||
def get_parent(obj):
|
||||
return obj.parent.id
|
||||
|
Reference in New Issue
Block a user