'Validates value and throws ValidationError. Subclasses should override
this to provide validation logic.'

def validate(self, value, model_instance):

    if (not self.editable):
        return
    if (self._choices and value):
        for (option_key, option_value) in self.choices:
            if isinstance(option_value, (list, tuple)):
                for (optgroup_key, optgroup_value) in option_value:
                    if (value == optgroup_key):
                        return
            elif (value == option_key):
                return
        raise exceptions.ValidationError((self.error_messages['invalid_choice'] % value))
    if ((value is None) and (not self.null)):
        raise exceptions.ValidationError(self.error_messages['null'])
    if ((not self.blank) and (value in validators.EMPTY_VALUES)):
        raise exceptions.ValidationError(self.error_messages['blank'])
