How can I make my model fields optional in Django?

后端 未结 1 1613
夕颜
夕颜 2021-02-04 07:15

I\'m trying to follow the full example at the bottom of

https://docs.djangoproject.com/en/dev/topics/auth/customizing/

In my model I have modified to the followi

相关标签:
1条回答
  • 2021-02-04 08:12

    You would have to add blank=True as well in field definition.

    date_of_birth = models.DateField(null=True, blank=True)
    

    From modelform doc

    If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True.

    Don't forget to reset and sync DB again after changing this.

    0 讨论(0)
提交回复
热议问题