Adds “NO SELECTION” to radio buttons form.

Closes #32.
This commit is contained in:
Christopher Neugebauer 2016-04-25 16:16:41 +10:00
parent 00f87e30b7
commit 2afa6a8d79

View file

@ -133,6 +133,9 @@ class _RadioButtonProductsForm(_ProductsForm):
choice_text = "%s -- $%d" % (product.name, product.price)
choices.append((product.id, choice_text))
if not category.required:
choices.append((0, "No selection"))
cls.base_fields[cls.FIELD] = forms.TypedChoiceField(
label=category.name,
widget=forms.RadioSelect,
@ -156,6 +159,8 @@ class _RadioButtonProductsForm(_ProductsForm):
ours = self.cleaned_data[self.FIELD]
choices = self.fields[self.FIELD].choices
for choice_value, choice_display in choices:
if choice_value == 0:
continue
yield (
choice_value,
1 if ours == choice_value else 0,