Merge pull request #3359 from raphaelmerx/master

DurationField accepts integers
This commit is contained in:
Tom Christie 2015-09-03 09:30:45 +01:00
commit ec007a7e2d
2 changed files with 2 additions and 1 deletions

View File

@ -1189,7 +1189,7 @@ class DurationField(Field):
def to_internal_value(self, value):
if isinstance(value, datetime.timedelta):
return value
parsed = parse_duration(value)
parsed = parse_duration(six.text_type(value))
if parsed is not None:
return parsed
self.fail('invalid', format='[DD] [HH:[MM:]]ss[.uuuuuu]')

View File

@ -1069,6 +1069,7 @@ class TestDurationField(FieldValues):
'3 08:32:01.000123': datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123),
'08:01': datetime.timedelta(minutes=8, seconds=1),
datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123): datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123),
3600: datetime.timedelta(hours=1),
}
invalid_inputs = {
'abc': ['Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].'],