Cannot successfully parse Django DateField in form -




i have: date_due = models.datefield(null=true, blank=true)

and related model form class in above occurs. other values validate fine in model form, when put in date in format august 25, 2017, receive error message: "enter valid date". in settings.py have set use_l10n = true (and set use_l18n = false ensure use_l10n setting being observed).

in the documentation says:

a list of formats accepted when inputting data on date field. formats tried in order, using first valid one. note these format strings use python’s datetime module syntax, not format strings date template filter.

and gives examples. using examples given, in settings have placed:

date_input_formats = [     '%b %d %y', '%b %d, %y',            # 'october 25 2006', 'october 25, 2006'     '%b %d %y', '%b %d, %y',            # 'oct 25 2006', 'oct 25, 2006'     '%y-%m-%d', '%m/%d/%y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'     '%d %b %y', '%d %b, %y',            # '25 october 2006', '25 october, 2006'     '%d %b %y', '%d %b, %y'             # '25 oct 2006', '25 oct, 2006' ] 

however, in format localization documentation (locale aware input in forms) says in note:

django uses different formats displaying data uses parsing data. notably, formats parsing dates can’t use %a (abbreviated weekday name), %a (full weekday name), %b (abbreviated month name), %b (full month name), or %p (am/pm).

these 2 sections of documentation seem in conflict , tend think latter correct because not honoring date_input_formats have specified. how can validate date in form: august 25, 2017?

further attempts: set use_l10n false , set use_i18n true , allows form accept dates formatted august 25, 2017, however, if try use time_input_formats , use example formats documentation (and setting use_l10n true), form not validate times in format: 5:00 pm. also, setting use_l10n true causes both date , time not pass forms validation. seems date_input_formats , time_input_formats don't work stated in documentation.

further attempt: imported date_input_formats forms settings , placed in init: self.fields['date_due'].input_formats = (date_input_formats) use_l10n still set true , use_i18n false, works validate date in format: august 25, 2017 same date_input_formats shown above. however, when tried same thing time (importing time_input_formats forms) , doing this:

self.fields['time_due'].input_formats = (time_input_formats) 

it still gives error when form validates time. here time formats:

time_input_formats = [     '%-i:%m %p',    # '2:30 am/pm'     '%-i:%m%p'      # '2:30am/pm' ] 

to reiterate, seems supposedly global date_input_formats , time_input_formats settings variables being ignored django. shouldn't have set these on every form in init.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -