diff --git a/django/forms/fields.py b/django/forms/fields.py index 09e20617ad..6d1c14586e 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -516,6 +516,7 @@ class DurationField(Field): def prepare_value(self, value): if isinstance(value, datetime.timedelta): return duration_string(value) + return value def to_python(self, value): if value in self.empty_values: diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 5f44811b93..477beee210 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -647,6 +647,7 @@ class FieldsTests(SimpleTestCase): field = DurationField() td = datetime.timedelta(minutes=15, seconds=30) self.assertEqual(field.prepare_value(td), duration_string(td)) + self.assertEqual(field.prepare_value('arbitrary'), 'arbitrary') self.assertIsNone(field.prepare_value(None)) # RegexField ##################################################################