python - Django datetimefield invalid for certain locales -
i don't have date input formats defined, form field is:
expiry_date = forms.datetimefield(widget=selectdatewidget, required=false) i'm using locales en (english) , zh-hans (simplified chinese).
according pycharm debugger, post values identical in either language:
self.request.post['expiry_date_day'] = u'25' self.request.post['expiry_date_month'] = u'9' self.request.post['expiry_date_year'] = u'2015' however error in zh-hans.
in form.clean() method self.cleaned_data['expiry_date'] value missing, i'm guessing it's being stripped out due failing previous validation error.
fixed:
i fixed adding following settings:
date_input_formats = ('%y-%m-%d', '%y/%m/%d') and apply specific datetimefield:
expiry_date = forms.datetimefield(widget=selectdatewidget, input_formats=settings.date_input_formats, required=false) specifically '%y-%m-%d' needed keep en happy, whilst '%y/%m/%d' allows zh-hans , zh-hant function correctly.
i found drilling down in debugger , figuring out value passing though datetimefield.to_python().
i'll leave question open though, i'd still understand exact why formatted differently locale, , if there's more obvious way figure out formats allow , when , don't think solution should "step-through debugger until find line of code!"
Comments
Post a Comment