diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 2e01634571..4f4d912c04 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -16,6 +16,7 @@ from django.utils.translation import ugettext from django.utils.encoding import StrAndUnicode, force_unicode from django.utils.safestring import mark_safe from django.utils import datetime_safe +from datetime import time from util import flatatt from urlparse import urljoin @@ -307,7 +308,7 @@ class TimeInput(Input): def render(self, name, value, attrs=None): if value is None: value = '' - elif hasattr(value, 'replace'): + elif isinstance(value, time): value = value.replace(microsecond=0) return super(TimeInput, self).render(name, value, attrs) diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py index e0d9f42db5..df0f5d6fd7 100644 --- a/tests/regressiontests/forms/widgets.py +++ b/tests/regressiontests/forms/widgets.py @@ -1104,5 +1104,9 @@ u'' u'' >>> w.render('time', datetime.time(12, 51)) u'' + +We should be able to initialize from a unicode value. +>>> w.render('time', u'13:12:11') +u'' """