diff options
| author | Fabien Bochu | 2015-01-19 10:57:26 +0100 | 
|---|---|---|
| committer | Fabien Bochu | 2015-01-19 13:09:08 +0100 | 
| commit | 5484d570cb8214c776273b45320e7d1c73b85a34 (patch) | |
| tree | a41483b39be63027acc7be6faac63a39c2c76167 /rest_framework/compat.py | |
| parent | 4f27b966a5954c56a96b298198ec93b69583dfad (diff) | |
| download | django-rest-framework-5484d570cb8214c776273b45320e7d1c73b85a34.tar.bz2 | |
Fix timedelta JSON serialization on Python 2.6.
Diffstat (limited to 'rest_framework/compat.py')
| -rw-r--r-- | rest_framework/compat.py | 8 | 
1 files changed, 8 insertions, 0 deletions
| diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 971dee9c..17814136 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -33,6 +33,14 @@ def unicode_to_repr(value):      return value +def total_seconds(timedelta): +    # TimeDelta.total_seconds() is only available in Python 2.7 +    if hasattr(timedelta, 'total_seconds'): +        return timedelta.total_seconds() +    else: +        return (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0) + +  # OrderedDict only available in Python 2.7.  # This will always be the case in Django 1.7 and above, as these versions  # no longer support Python 2.6. | 
