пятница, 14 декабря 2012 г.

DateTimeField doesn't accept ISO 8601 formatted date string



You can find roots of this problem here in django sources and here in python bugs.

You can even find some solutions for this problem which suggests you to append extended patterns (with %z key) to DATETIME_INPUT_FORMATS, but they doesn't work in most cases.

So here is my workaround to solve this problem: just install python-dateutil package and add to your settings.py following lines:

# Patch datetime field parser
from dateutil import parser
from django.forms import fields
fields.DateTimeField.strptime = lambda o, v, f: parser.parse(v)

Комментариев нет:

Отправить комментарий