For example, I have a model like this:
class Item(models.Model): TYPE_CHOICES = ( (1, _('type 1')), (2, _('type 2')), ) type = models.PositiveSmallIntegerField(max_length=1, choices=TYPE_CHOICES)
And for the form, I have:
class ItemModelForm(forms.ModelForm): class Meta: model = Item widget = { 'type': forms.RadioSelect(), }
What I would like to have is to select a radio with two parameters ("type 1" and "type 2"). However, I will have 3 options: "---------", "type 1" and "type 2". "---------" for "No", I think, but the "type" field is required in the model, why is the "No" parameter still displayed?
But if I use a form instead:
class ItemForm(forms.Form): type = forms.ChoiceField(widget=forms.RadioSelect(), choices=Item.TYPE_CHOICES)
I will have only 2 options: "type 1" and "type 2", which is correct.
I would like to use ModelForm over the standard form, but donโt know how to remove "---------". Can anyone help me out? Thanks.
UPDATE: Thank you guys just found the answer to here .
Looks like I have to override the method or ModelForm.