[Answered ]-Change widget from select to check box in generic class based view

2👍

You can define a custom form and customise the widget there:

class PublisherForm(forms.ModelForm):
    class Meta
        model = Publisher
        fields = ['name', 'address', 'city', 'state_province', 'country',  'website']
        widgets = {
            'country': forms.RadioSelect,
        }

I’ve used radio select here. It doesn’t really make sense to use checkboxes because you only want one choice to be selected.

Then use the form in the view:

class PublisherCreate(CreateView):
    model = Server
    form_class = PublisherForm

Leave a comment