[1.1.X] Fixed #12059 - Let TimeField.to_python correctly return a datetime.time object when having a datetime object.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12237 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-01-17 22:09:33 +00:00
parent 4d409c0b3b
commit 3a6f58a169
2 changed files with 10 additions and 1 deletions

View File

@ -859,7 +859,7 @@ class TimeField(Field):
# Not usually a good idea to pass in a datetime here (it loses
# information), but this can be a side-effect of interacting with a
# database backend (e.g. Oracle), so we'll be accommodating.
return value.time
return value.time()
# Attempt to parse a datetime:
value = smart_str(value)

View File

@ -58,6 +58,15 @@ datetime.time(5, 30)
>>> d3.consumed_at
datetime.datetime(2007, 4, 20, 16, 19, 59)
# Test for ticket #12059: TimeField wrongly handling datetime.datetime object.
>>> d2.baked_time = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
>>> d2.save()
>>> d3 = Donut.objects.all()[0]
>>> d3.baked_time
datetime.time(16, 19, 59)
# Year boundary tests (ticket #3689)
>>> d = Donut(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))