mirror of
https://github.com/django/django.git
synced 2025-09-23 10:42:45 +00:00
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
This commit is contained in:
parent
db80f57c6e
commit
a97f690e5d
3 changed files with 53 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue