I have been able to get the BooleanField from my main Feature class to be rendered as a radiobutton for its form, but when viewed, the form doesn’t have the corresponding value preselected. How do I get it to select the appropriate one, given a boolean value? Thanks
models.py:
class Feature(models.Model):
for_biz = models.BooleanField()
class FeatureForm(ModelForm):
choices = ( (1,'Business'), (0, 'Customers') )
for_biz = forms.TypedChoiceField(
coerce=lambda x: bool(int(x)),
choices=choices,
widget=forms.RadioSelect,
)
class Meta:
model = Feature
fields = (
'for_biz',
)
views.py:
def edit_feature(request, f_id):
f = get_object_or_404(Feature, id=f_id)
form = FeatureForm(instance=f)
....
Make it a
PositiveSmallIntegerFieldwithchoices.BooleanFielddoesn’t really buy you anything, and as you already saw it only gives you more trouble to deal with.