aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils/encoders.py
diff options
context:
space:
mode:
authorTom Christie2013-01-22 09:11:38 +0000
committerTom Christie2013-01-22 09:11:38 +0000
commitb7ab2aee46c718f683b19eefba1b48f233da40e4 (patch)
tree1af09c7dbcc939c749d30adf25b14d232200f44f /rest_framework/utils/encoders.py
parent65b62d64ec54b528b62a1500b8f6ffe216d45c09 (diff)
parente29ba356f054222893655901923811bd9675d4cc (diff)
downloaddjango-rest-framework-b7ab2aee46c718f683b19eefba1b48f233da40e4.tar.bz2
Merge branch 'master' into unauthenticated_response
Conflicts: docs/api-guide/authentication.md
Diffstat (limited to 'rest_framework/utils/encoders.py')
-rw-r--r--rest_framework/utils/encoders.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index c70b24dd..7afe100a 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -12,7 +12,7 @@ from rest_framework.serializers import DictWithMetadata, SortedDictWithMetadata
class JSONEncoder(json.JSONEncoder):
"""
- JSONEncoder subclass that knows how to encode date/time,
+ JSONEncoder subclass that knows how to encode date/time/timedelta,
decimal types, and generators.
"""
def default(self, o):
@@ -34,6 +34,8 @@ class JSONEncoder(json.JSONEncoder):
if o.microsecond:
r = r[:12]
return r
+ elif isinstance(o, datetime.timedelta):
+ return str(o.total_seconds())
elif isinstance(o, decimal.Decimal):
return str(o)
elif hasattr(o, '__iter__'):