borodenkov-s
12/5/2013 - 6:32 PM

django form clean conditianal empty values

django form clean conditianal empty values

from django.core.validators import EMPTY_VALUES

def clean(self):
    cleaned_data = self.cleaned_data
    some_value = cleaned_data.get('rework_comment', None)
    if some_condition and some_value in EMPTY_VALUES:
        self._errors['field_name'] = self.error_class(unicode([self.fields['field_name'].error_messages['required']]))
    return cleaned_data