[Bugfix] 修复创建node api的bug

pull/1331/merge
ibuler 2018-05-15 15:05:49 +08:00
parent cb4afabc91
commit ed18cb317f
1 changed files with 7 additions and 8 deletions

View File

@ -53,14 +53,13 @@ class NodeSerializer(serializers.ModelSerializer):
def validate(self, data):
value = data.get('value')
instance = self.instance
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 serializers.ValidationError(
'The same level node name cannot be the same'
)
instance = self.instance if self.instance else Node.root()
children = instance.parent.get_children().exclude(key=instance.key)
values = [child.value for child in children]
if value in values:
raise serializers.ValidationError(
'The same level node name cannot be the same'
)
return data
@staticmethod