aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils/encoders.py
diff options
context:
space:
mode:
authorMathieu Pillard2014-01-17 13:05:10 +0100
committerMathieu Pillard2014-01-17 13:05:10 +0100
commitf034cb595ae0b9091a9eb68a2b583a320ef39c4e (patch)
tree8dd389c3233fa722219a10bffa2deec748e20bd7 /rest_framework/utils/encoders.py
parent71c03b9db97edbde228777981de0ac7b664302de (diff)
downloaddjango-rest-framework-f034cb595ae0b9091a9eb68a2b583a320ef39c4e.tar.bz2
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__'):