aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils/encoders.py
diff options
context:
space:
mode:
authorTom Christie2014-01-17 04:28:01 -0800
committerTom Christie2014-01-17 04:28:01 -0800
commit92fe7560bd69bd2acfe7a3ee2034ecd70e13b0f9 (patch)
tree8dd389c3233fa722219a10bffa2deec748e20bd7 /rest_framework/utils/encoders.py
parent71c03b9db97edbde228777981de0ac7b664302de (diff)
parentf034cb595ae0b9091a9eb68a2b583a320ef39c4e (diff)
downloaddjango-rest-framework-92fe7560bd69bd2acfe7a3ee2034ecd70e13b0f9.tar.bz2
Merge pull request #1360 from diox/fix-querysets-json-encoding
Encode django QuerySets to lists and not dicts in JSONEncoder
Diffstat (limited to 'rest_framework/utils/encoders.py')
-rw-r--r--rest_framework/utils/encoders.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index 3ac920c6..e5fa4194 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -2,6 +2,7 @@
Helper classes for parsers.
"""
from __future__ import unicode_literals
+from django.db.models.query import QuerySet
from django.utils.datastructures import SortedDict
from django.utils.functional import Promise
from rest_framework.compat import timezone, force_text
@@ -42,6 +43,8 @@ class JSONEncoder(json.JSONEncoder):
return str(o.total_seconds())
elif isinstance(o, decimal.Decimal):
return str(o)
+ elif isinstance(o, QuerySet):
+ return list(o)
elif hasattr(o, 'tolist'):
return o.tolist()
elif hasattr(o, '__getitem__'):