From f034cb595ae0b9091a9eb68a2b583a320ef39c4e Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Fri, 17 Jan 2014 13:05:10 +0100 Subject: Encode django QuerySets to lists and not dicts in JSONEncoder --- rest_framework/utils/encoders.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'rest_framework/utils') 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__'): -- cgit v1.2.3 From 613df5c6501f715c0775229f34fcba9f4291c05d Mon Sep 17 00:00:00 2001 From: Ian Leith Date: Fri, 11 Apr 2014 05:49:49 +0100 Subject: Fix dict_keys equality test for python 3. --- rest_framework/utils/mediatypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/utils') diff --git a/rest_framework/utils/mediatypes.py b/rest_framework/utils/mediatypes.py index c09c2933..92f99efd 100644 --- a/rest_framework/utils/mediatypes.py +++ b/rest_framework/utils/mediatypes.py @@ -74,7 +74,7 @@ class _MediaType(object): return 0 elif self.sub_type == '*': return 1 - elif not self.params or self.params.keys() == ['q']: + elif not self.params or list(self.params.keys()) == ['q']: return 2 return 3 -- cgit v1.2.3