summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-20 22:38:15 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-20 22:38:15 +0000
commitb9407b26dff47232d57133d93593a1a50eee1cc5 (patch)
treef0b215f1d01038a3b8511e6b2fca9506916970a8 /django/db/models/sql
parenteb85af18652f4096b6abbad8915a554b4d51865e (diff)
Made it possible to pickle DateQuerySets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8455 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/datastructures.py2
-rw-r--r--django/db/models/sql/subqueries.py17
2 files changed, 18 insertions, 1 deletions
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index cb54a564f8..913d8fde25 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -85,7 +85,7 @@ class Date(object):
def __init__(self, col, lookup_type, date_sql_func):
self.col = col
self.lookup_type = lookup_type
- self.date_sql_func= date_sql_func
+ self.date_sql_func = date_sql_func
def relabel_aliases(self, change_map):
c = self.col
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index 5ca041cbde..cea2a58d39 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -343,6 +343,23 @@ class DateQuery(Query):
date field. This requires some special handling when converting the results
back to Python objects, so we put it in a separate class.
"""
+ def __getstate__(self):
+ """
+ Special DateQuery-specific pickle handling.
+ """
+ for elt in self.select:
+ if isinstance(elt, Date):
+ # Eliminate a method reference that can't be pickled. The
+ # __setstate__ method restores this.
+ elt.date_sql_func = None
+ return super(DateQuery, self).__getstate__()
+
+ def __setstate__(self, obj_dict):
+ super(DateQuery, self).__setstate__(obj_dict)
+ for elt in self.select:
+ if isinstance(elt, Date):
+ self.date_sql_func = self.connection.ops.date_trunc_sql
+
def results_iter(self):
"""
Returns an iterator over the results from executing this query.