Django: Make certain fields in a ModelForm required=False

后端 未结 5 1956
无人共我
无人共我 2021-02-02 06:08

How do I make certain fields in a ModelForm required=False?

If I have:

class ThatForm(ModelForm):
  class Meta:
    widgets = {\"text\": Textarea(require         


        
5条回答
  •  旧巷少年郎
    2021-02-02 07:03

    you ought to add blank=True to the corresponding model

    The documentation says

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

    Also see the documentation for blank itself.

提交回复
热议问题