summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-28 14:14:41 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-28 14:14:41 +0000
commita97f690e5dbfe9c8d1034a94373da0bedd681814 (patch)
tree37af78519f531c49f35d89b42a87ae0e0b1012ba /django
parentdb80f57c6efb23304eb9fb7899b078a85836f850 (diff)
Added the ability to pickle and unpickle QuerySets and Query classes.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py13
-rw-r--r--django/db/models/sql/query.py18
2 files changed, 30 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 3011b9d9a6..65048c7ba8 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -28,6 +28,17 @@ class QuerySet(object):
# PYTHON MAGIC METHODS #
########################
+ def __getstate__(self):
+ """
+ Allows the Queryset to be pickled.
+ """
+ # Force the cache to be fully populated.
+ len(self)
+
+ obj_dict = self.__dict__.copy()
+ obj_dict['_iter'] = None
+ return obj_dict
+
def __repr__(self):
return repr(list(self))
@@ -37,7 +48,7 @@ class QuerySet(object):
# whilst not messing up any existing iterators against the queryset.
if self._result_cache is None:
if self._iter:
- self._result_cache = list(self._iter())
+ self._result_cache = list(self._iter)
else:
self._result_cache = list(self.iterator())
elif self._iter:
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index bfed984953..7e9fb00418 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -99,6 +99,24 @@ class Query(object):
memo[id(self)] = result
return result
+ def __getstate__(self):
+ """
+ Pickling support.
+ """
+ obj_dict = self.__dict__.copy()
+ del obj_dict['connection']
+ return obj_dict
+
+ def __setstate__(self, obj_dict):
+ """
+ Unpickling support.
+ """
+ self.__dict__.update(obj_dict)
+ # XXX: Need a better solution for this when multi-db stuff is
+ # supported. It's the only class-reference to the module-level
+ # connection variable.
+ self.connection = connection
+
def get_meta(self):
"""
Returns the Options instance (the model._meta) from which to start