#11385: DateTimeField doesn't accept ISO 8601 formatted date string -------------------------------------+------------------------------------ Reporter: jtiai | Owner: nobody Type: New feature | Status: new Component: Forms | Version: master Severity: Normal | Resolution: Keywords: datetime orm format | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------
Comment (by julen): As kmike mentioned above, customizing the form field with an `input_formats` containing the timezone marker `%z` doesn't help — at least on Python 2.7. For anyone hitting this, I worked around it by using a custom form field and overriding the `strptime` method: {{{ from django.utils.dateparse import parse_datetime from django.utils.encoding import force_str class ISODateTimeField(forms.DateTimeField): def strptime(self, value, format): return parse_datetime(force_str(value)) }}} I use Django's own `parse_datetime` utility. Note this is limited to ISO datetimes, and effectively any `input_formats` are omitted. -- Ticket URL: <https://code.djangoproject.com/ticket/11385#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.bc7bc24299f6804106d21298db5ca74e%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.