Monday, September 29, 2014

Force date and time formats to ISO

Hello to the list,
I am developing a Django website that needs USE_L10N = True, and
per-user TZ settings, but I want to force the output of dates and times
to ISO everywhere, once and for all (YYYY-MM-DD and HH:MM:SS).

I understand that Django with USE_L10N = True overrides the output of
DateField, DateTimeField, TimeField to follow the locale format, but I
need the format of my choice everywhere.

For the output in templates I came to this solution: write a
templatefilter that does the localtime -> strftime steps, and it works.

But to be the definitive solution also form fields when doing CRUD on my
database objects must accept and show dates and datetimes in that format.

I'm thinking that I have to write custom form fields like
ISO_DateField(django.forms.DateField),
ISO_DateTimeField(django.forms.DateTimeField) and
ISO_TimeField(django.forms.TimeField) overriding their methods to do
what I need.

Is there a better way?

Thanks in advance,
Mark

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/542951AE.9040406%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment