示例#1
0
    def validate_tags(self, attrs, source):
        value = attrs[source]
        tags = clean_and_split_tags(value)
        if len(tags) < 3:
            raise serializers.ValidationError('Your should at least have 3 tags...')
        elif len(tags) > 30:
            raise serializers.ValidationError('There can be maximum 30 tags, please select the most relevant ones!')

        return attrs
示例#2
0
 def validate_tags(self, attrs, source):
     if not self.is_providing_description(attrs):
         attrs[source] = None
     else:
         value = attrs[source]
         tags = clean_and_split_tags(value)
         if len(tags) < 3:
             raise serializers.ValidationError('You should at least have 3 tags...')
         elif len(tags) > 30:
             raise serializers.ValidationError('There can be maximum 30 tags, please select the most relevant ones!')
         attrs[source] = tags
     return attrs