def _process_field_error(self, e: InvalidModelFieldError, field: str): if not e.field: e.field = field if not e.model: e.model = self raise e
def validate(self, value): if not value: return if not isinstance(value, self.type): raise InvalidModelFieldError( "should be an instance of '{}'".format(self.type.__name__))
def __set__(self, instance, value): if value is not None and not isinstance(value, self.model): try: value = self.model(value) except ValueError: available = [e.value for e in self.model] raise InvalidModelFieldError("{0} is not a valid option. Use one of {1}".format(value, available)) super().__set__(instance, value)
def validate(self, value): if not value: return if not isinstance(value, collections.MutableSequence): raise InvalidModelFieldError('should be a list') for i in value: for validator in self.validators: validator(i)
def validate(self, value): if not value: return if value not in self.choices: raise InvalidModelFieldError('{0} should be in {1}'.format(value, self.choices))
def validate(self, value): if not value: return if not isinstance(value, bool): raise InvalidModelFieldError('{0} should be a boolean'.format(value))
def validate(self, value): if not value: return if not isinstance(value, int): raise InvalidModelFieldError('{0} should be an integer'.format(value))
def validate(self, value): if not value: return if not isinstance(value, str): raise InvalidModelFieldError('{0} should be a string'.format(value))
def validate(self, value): if value is None: raise InvalidModelFieldError('is required')
def validate(self, value): if not value: return if not isinstance(value, float): raise InvalidModelFieldError("{0} should be a float".format(value))