My model form inherit from subsystem form.
I want to limit choices for the user in the form. (specially the name)
I know I have to use widgets. But It doesn’t work.
I have to use SubsytemForm.
SUBSYSTEM_CHOICES = (a1,a2,a3)
class Subsystem(models.Model):
name = models.CharField("Name", max_length=20)
class SubsytemForm(forms.ModelForm):
class Meta:
model = Subsystem
widgets = {
'name': ChoiceField(widget=RadioSelect, choices=SUBSYSTEM_CHOICES)
}
From django model forms documentation:
You can try with:
Also you can
and send
name_choicesas parameter inSubsytemFormcreation. Remember that choices should be a query set.Also, you should read How do I filter ForeignKey choices in a Django ModelForm?