{{{#!python
#in forms.py
class TimingForm(forms.ModelForm):
TIMING_LEVEL_CHOICES = ( (False, "Time Whole Lines (recommended)"),
(True, "Time Individual Words"), )
word_level_timing = forms.ChoiceField(label='Timing Level',
required=True, widget=forms.RadioSelect, choices=TIMING_LEVEL_CHOICES,
initial=False)
class Meta:
model = TimingThingie
fields = ['word_level_timing']
#in models.py
class TimingThingie(models.Model):
word_level_timing = models.BooleanField(default=False)
#in views.py:
def modify_timing(request, tinstance_id):
tinstance = TimingThingie.objects.get(id=tinstance_id)
if tinstance.word_level_timing !=
boolform.cleaned_data["word_level_timing"]:
#one is False, the other is 'False', inequality is true against
intent and likely introduces a bug
pass
if tinstance.word_level_timing !=
bool(strtobool(form.cleaned_data["word_level_timing"])):
#this works correctly, but is ugly and born only through suffering
pass
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31971>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
New description:
form.cleaned_data["word_level_timing"]:
#one is False, the other is 'False', inequality is true against
intent and likely introduces a bug
pass
if tinstance.word_level_timing !=
bool(strtobool(form.cleaned_data["word_level_timing"])):
#this works correctly, but is ugly and born only through suffering
pass
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31971#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
You should use a `BooleanField` with a different widget not a
`ChoiceField`, if you want to get data as booleans, e.g.
{{{
word_level_timing =
forms.BooleanField(widget=forms.RadioSelect(choices=TIMING_LEVEL_CHOICES))
}}}
I don't see a reason to add a new field to Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/31971#comment:2>