DateTimeField can now clean values that come from SplitDateTimeWidget.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-21 14:50:20 +00:00
parent d79c6a0125
commit f5831b03c9
1 changed files with 6 additions and 0 deletions

View File

@ -300,6 +300,12 @@ class DateTimeField(Field):
return value
if isinstance(value, datetime.date):
return datetime.datetime(value.year, value.month, value.day)
if isinstance(value, list):
# Input comes from a SplitDateTimeWidget, for example. So, it's two
# components: date and time.
if len(value) != 2:
raise ValidationError(ugettext(u'Enter a valid date/time.'))
value = '%s %s' % tuple(value)
for format in self.input_formats:
try:
return datetime.datetime(*time.strptime(value, format)[:6])