Django modelform NOT required field

后端 未结 7 1131
一整个雨季
一整个雨季 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:33

    field = models.CharField(max_length=9, default='', blank=True)
    

    Just add blank=True in your model field and it won't be required when you're using modelforms.

    source: https://docs.djangoproject.com/en/3.1/topics/forms/modelforms/#field-types

提交回复
热议问题