Fixed #24897 -- Allowed using choices longer than 1 day with DurationField
This commit is contained in:
parent
3222fc7943
commit
262d4db8c4
|
@ -29,7 +29,7 @@ datetime_re = re.compile(
|
|||
|
||||
standard_duration_re = re.compile(
|
||||
r'^'
|
||||
r'(?:(?P<days>-?\d+) )?'
|
||||
r'(?:(?P<days>-?\d+) (days?, )?)?'
|
||||
r'((?:(?P<hours>\d+):)(?=\d+:\d+))?'
|
||||
r'(?:(?P<minutes>\d+):)?'
|
||||
r'(?P<seconds>\d+)'
|
||||
|
|
|
@ -40,3 +40,6 @@ Bugfixes
|
|||
|
||||
* Fixed queryset pickling when using ``prefetch_related()`` after deleting
|
||||
objects (:ticket:`24831`).
|
||||
|
||||
* Allowed using ``choices`` longer than 1 day with ``DurationField``
|
||||
(:ticket:`24897`).
|
||||
|
|
|
@ -51,6 +51,20 @@ class DateParseTests(unittest.TestCase):
|
|||
|
||||
|
||||
class DurationParseTests(unittest.TestCase):
|
||||
|
||||
def test_parse_python_format(self):
|
||||
timedeltas = [
|
||||
timedelta(days=4, minutes=15, seconds=30, milliseconds=100), # fractions of seconds
|
||||
timedelta(hours=10, minutes=15, seconds=30), # hours, minutes, seconds
|
||||
timedelta(days=4, minutes=15, seconds=30), # multiple days
|
||||
timedelta(days=1, minutes=00, seconds=00), # single day
|
||||
timedelta(days=-4, minutes=15, seconds=30), # negative durations
|
||||
timedelta(minutes=15, seconds=30), # minute & seconds
|
||||
timedelta(seconds=30), # seconds
|
||||
]
|
||||
for delta in timedeltas:
|
||||
self.assertEqual(parse_duration(format(delta)), delta)
|
||||
|
||||
def test_seconds(self):
|
||||
self.assertEqual(parse_duration('30'), timedelta(seconds=30))
|
||||
|
||||
|
|
Loading…
Reference in New Issue