Django modelform NOT required field

后端 未结 7 1130
一整个雨季
一整个雨季 2021-01-30 01:54

I have a form like this:

class My_Form(ModelForm):
    class Meta:
        model = My_Class
        fields = (\'first_name\', \'last_name\' , \'address\')
         


        
7条回答
  •  盖世英雄少女心
    2021-01-30 02:36

    class My_Form(forms.ModelForm):
        class Meta:
            model = My_Class
            fields = ('first_name', 'last_name' , 'address')
    
        def __init__(self, *args, **kwargs):
            super(My_Form, self).__init__(*args, **kwargs)
            self.fields['address'].required = False
    

提交回复
热议问题