class MyChoiceField forms ChoiceField EMPTY_VALUES None def clean self

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class MyChoiceField(forms.ChoiceField):
EMPTY_VALUES = (None, '')
def clean(self, value):
"""
Validates that the input is in self.choices.
"""
from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str
if value in self.EMPTY_VALUES:
value = u''
value = smart_unicode(value)
if value == u'':
return value
return value