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