Created
October 6, 2021 10:41
-
-
Save TSKGunGun/ae926ac6aa5d23a130210acc841d97e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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