[Django]-Many to Many relation' list display with checkbox in Django

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')
👤arjun

Leave a comment