def validate(self, instance): val = getattr(instance, self.name) errors = [] # type_validation if val and not isinstance(val, self.acceptable_types()): errors.append(( self.name, 'bad type', )) # validate first standard stuff if self.required: if val is None or not unicode(val).strip(): errors.append((self.name, 'required')) # validate uniquness if val and self.unique: error = self.validate_uniqueness(instance, val) if error: errors.append(error) # validate using validator if self.validator: r = self.validator(self.name, val) if r: errors.extend(r) if errors: raise FieldValidationError(errors)
def validate(self, instance): errors = [] try: super(CharField, self).validate(instance) except FieldValidationError as err: errors.extend(err.errors) val = getattr(instance, self.name) if val and len(val) > self.max_length: errors.append((self.name, 'exceeds max length')) if errors: raise FieldValidationError(errors)
def validate(self, instance): val = getattr(instance, self.name) errors = [] if val: if not isinstance(val, self.value_type()): errors.append((self.name, 'bad type for reference')) # validate first standard stuff if self.required: if not val: errors.append((self.name, 'required')) # validate using validator if self.validator: r = self.validator(val) if r: errors.extend(r) if errors: raise FieldValidationError(errors)