django forms dateField fails validation

坚强是说给别人听的谎言 提交于 2019-12-05 13:18:10
SaeX

With Django 1.6 and up you can use the localized_fields in your form's Meta or localize=True in your form. See https://docs.djangoproject.com/en/1.9/topics/i18n/formatting/#format-localization.

When using USE_L10N = True, Django will use the formats.py file for your locale (part of LANGUAGE_CODE).

You can end up with something DRY like this (as the fields specified in models.py do not need to be repeated in forms.py):

class SomeForm(forms.Form):

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