Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
ec007a7e
Commit
ec007a7e
authored
Sep 03, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3359 from raphaelmerx/master
DurationField accepts integers
parents
d48ec836
b9782b68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
1 deletions
+2
-1
rest_framework/fields.py
+1
-1
tests/test_fields.py
+1
-0
No files found.
rest_framework/fields.py
View file @
ec007a7e
...
@@ -1189,7 +1189,7 @@ class DurationField(Field):
...
@@ -1189,7 +1189,7 @@ class DurationField(Field):
def
to_internal_value
(
self
,
value
):
def
to_internal_value
(
self
,
value
):
if
isinstance
(
value
,
datetime
.
timedelta
):
if
isinstance
(
value
,
datetime
.
timedelta
):
return
value
return
value
parsed
=
parse_duration
(
value
)
parsed
=
parse_duration
(
six
.
text_type
(
value
)
)
if
parsed
is
not
None
:
if
parsed
is
not
None
:
return
parsed
return
parsed
self
.
fail
(
'invalid'
,
format
=
'[DD] [HH:[MM:]]ss[.uuuuuu]'
)
self
.
fail
(
'invalid'
,
format
=
'[DD] [HH:[MM:]]ss[.uuuuuu]'
)
...
...
tests/test_fields.py
View file @
ec007a7e
...
@@ -1069,6 +1069,7 @@ class TestDurationField(FieldValues):
...
@@ -1069,6 +1069,7 @@ class TestDurationField(FieldValues):
'3 08:32:01.000123'
:
datetime
.
timedelta
(
days
=
3
,
hours
=
8
,
minutes
=
32
,
seconds
=
1
,
microseconds
=
123
),
'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
),
'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
),
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
=
{
invalid_inputs
=
{
'abc'
:
[
'Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].'
],
'abc'
:
[
'Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].'
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment