Make ReturnDict cachable. Closes #2360. · encode/django-rest-framework@e59b3d1 (original) (raw)

Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ def copy(self):
19 19 def __repr__(self):
20 20 return dict.__repr__(self)
21 21
22 +def __reduce__(self):
23 +# Pickling these objects will drop the .serializer backlink,
24 +# but preserve the raw data.
25 +return (dict, (dict(self),))
26 +
22 27
23 28 class ReturnList(list):
24 29 """
@@ -33,6 +38,11 @@ def __init__(self, *args, **kwargs):
33 38 def __repr__(self):
34 39 return list.__repr__(self)
35 40
41 +def __reduce__(self):
42 +# Pickling these objects will drop the .serializer backlink,
43 +# but preserve the raw data.
44 +return (list, (list(self),))
45 +
36 46
37 47 class BoundField(object):
38 48 """