Fixed #26104 -- Fixed TypeError when passing number to forms.DurationField.

This commit is contained in:
Alexander Gaevsky 2016-01-22 21:33:21 +02:00 committed by Tim Graham
parent 95648eb5c1
commit 956cde8004
2 changed files with 5 additions and 1 deletions

View File

@ -488,7 +488,7 @@ class DurationField(Field):
return None
if isinstance(value, datetime.timedelta):
return value
value = parse_duration(value)
value = parse_duration(force_str(value))
if value is None:
raise ValidationError(self.error_messages['invalid'], code='invalid')
return value

View File

@ -722,6 +722,10 @@ class FieldsTests(SimpleTestCase):
str(f['duration'])
)
def test_durationfield_integer_value(self):
f = DurationField()
self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800))
def test_durationfield_prepare_value(self):
field = DurationField()
td = datetime.timedelta(minutes=15, seconds=30)