def clean(self, value):
"""
Validates that the input is in self.choices.
"""
value = super(GroupedChoiceField, self).clean(value)
if value in (None, ''):
value = u''
value = forms.util.smart_unicode(value)
if value == u'':
return value
valid_values = []
for choice in self.choices:
group = choice[1]
valid_values += [str(key) for key, value in group]
if value not in valid_values:
raise ValidationError(_(u'Select a valid choice. That choice is not one of the available choices.'))
return value
评论列表
文章目录