3👍
✅
You can set the widget to a CheckboxSelectMultiple
widget [Django-doc]:
class DoctorForm(forms.ModelForm):
class Meta:
model = Doctor
fields = ('name','speciality','contact','clinic_hospital')
widgets = {
'clinic_hospital': forms.CheckboxSelectMultiple
}
1👍
You can use CheckboxSelectMultiple .For example if clinic_hospital
is your ManyToMany field and you want to display it as a checkbox then you can try like this
class DoctorForm(forms.ModelForm):
clinic_hospital= forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple)
class Meta():
model = Doctor
fields = ('name','speciality','contact','clinic_hospital')
- [Django]-Debugging Django Forms validation errors
- [Django]-Django i18n + template include tags
- [Django]-Heroku can't find Django templates
- [Django]-Import Django Model Serializer and Use it in Model's Save Method
- [Django]-Django move data from local to production?
Source:stackexchange.com