How can I set a DateField format in django from the model?

↘锁芯ラ 提交于 2019-12-02 22:00:10

As @bruno as mentioned in his answer, input_formats is a forms field, however it can be use to control the date format saved from the model.

In settings.py set DATE_INPUT_FORMATS as below:

DATE_INPUT_FORMATS = ['%d-%m-%Y']

And in your form you could do something like below:

class ClientDetailsForm(ModelForm):
    date_of_birth = DateField(input_formats=settings.DATE_INPUT_FORMATS)
    class Meta:
       model = ModelA

input_formats is a forms.DateField option, not a model.DateField option. You have to set it in your form, not in your models.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!