Created
July 4, 2010 04:43
-
-
Save rctay/463135 to your computer and use it in GitHub Desktop.
[django] clean field
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
from clean_field import * |
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
from django.forms.util import ValidationError | |
def clean_field(form, field_name): | |
""" | |
Get the cleaned value of a field, without requiring the entire form to be | |
valid. | |
""" | |
try: | |
return form.fields[field_name].clean(form.data.get(field_name, None)) | |
except ValidationError: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment