Skip to content

Instantly share code, notes, and snippets.

@TSKGunGun
Created October 6, 2021 10:41
Show Gist options
  • Save TSKGunGun/ae926ac6aa5d23a130210acc841d97e8 to your computer and use it in GitHub Desktop.
Save TSKGunGun/ae926ac6aa5d23a130210acc841d97e8 to your computer and use it in GitHub Desktop.
def run_validators(self, value):
if value in self.empty_values:
return
errors = []
for v in self.validators:
try:
v(value)
except exceptions.ValidationError as e:
if hasattr(e, 'code') and e.code in self.error_messages:
e.message = self.error_messages[e.code]
errors.extend(e.error_list)
if errors:
raise exceptions.ValidationError(errors)
def clean(self, value, model_instance):
"""
Convert the value's type and run validation. Validation errors
from to_python() and validate() are propagated. Return the correct
value if no error is raised.
"""
value = self.to_python(value)
self.validate(value, model_instance)
self.run_validators(value)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment