Skip to content

Instantly share code, notes, and snippets.

View souen's full-sized avatar

Souen Boniface souen

View GitHub Profile
@souen
souen / gist:651289
Created October 28, 2010 13:06 — forked from davidbgk/fields.py
class EmptyChoiceField(forms.ChoiceField):
def __init__(self, choices=(), empty_label=None, required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):
# add an empty label if it exists (and if field is not required!)
if not required and empty_label is not None:
choices = tuple([(u'', empty_label)] + list(choices))
super(EmptyChoiceField, self).__init__(choices=choices, required=required, widget=widget, label=label,
initial=initial, help_text=help_text, *args, **kwargs)