How to insert a checkbox in a django form

后端 未结 4 813
猫巷女王i
猫巷女王i 2021-01-30 13:32

I\'ve a settings page where users can select if they want to receive a newsletter or not.

I want a checkbox for this, and I want that Django select it if \'newsletter\'

4条回答
  •  没有蜡笔的小新
    2021-01-30 13:36

    class PlanYourHouseForm(forms.ModelForm):
    
        class Meta:
            model = PlanYourHouse
            exclude = ['is_deleted'] 
            widgets = {
                'is_anything_required' : CheckboxInput(attrs={'class': 'required checkbox form-control'}),   
            }
    

提交回复
热议问题