Here's my attempt to help others looking into using RadioSelect, CheckboxSelectMultiple, or the SelectDateWidget.
These are all excellent features and the more I use Django, the more I like it. Chalk up Forms as another part of django that blows away any other web framework I've worked with.
from django.forms.fields import ChoiceField
from django.forms.fields import MultipleChoiceField
from django.forms.widgets import RadioSelect
from django.forms.widgets import CheckboxSelectMultiple
from django.forms.extras.widgets import SelectDateWidget
YEAR_CHOICES = ('2010','2009')
RADIO_CHOICES = [['1','Radio 1'],['2','Radio 2']]
CHECKBOX_CHOICES = (('1','The first choice'),('2','The Second Choice'))
class SimpleForm(forms.Form):
radio = forms.ChoiceField( widget=RadioSelect(), choices=RADIO_CHOICES)
date = forms.DateField(widget=SelectDateWidget(None,YEAR_CHOICES) )
checkboxes = forms.MultipleChoiceField( required=False,
widget=CheckboxSelectMultiple(), choices=CHECKBOX_CHOICES)
This was *exactly* what I was looking for. Thanks.
ReplyDeleteAs above. Why is this *ESSENTIAL* information not in the django docs?!? Madness!!!
ReplyDeleteThis has just saved me from the biggest headache ever.
ReplyDeleteYou should import with a " ," it easier .
ReplyDeletefrom django.forms.fields import
ChoiceField,MultipleChoiceField
Thanks! This was incredibly helpful.
ReplyDeleteThanks so much! This is what I want
ReplyDeleteThis was what I needed exactly
ReplyDelete