diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-03-27 15:54:31 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-03-27 15:54:31 +0000 |
| commit | ad5afd6ed220ed50a2b48d7ccf9786ac0e52f807 (patch) | |
| tree | 14caa228c595f66afdaa130c1d2fe2db238ee312 /django/db/models/fields | |
| parent | b31b2d4da3772463d007c9d986c4bdd1392b09e7 (diff) | |
Fixed #12769, #12924 -- Corrected the pickling of curried and lazy objects, which was preventing queries with translated or related fields from being pickled. And lo, Alex Gaynor didst slayeth the dragon.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12866 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/fields')
| -rw-r--r-- | django/db/models/fields/__init__.py | 28 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 8 |
2 files changed, 4 insertions, 32 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 467d13a6f4..281963f3f5 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -119,34 +119,6 @@ class Field(object): messages.update(error_messages or {}) self.error_messages = messages - def __getstate__(self): - """ - Pickling support. - """ - from django.utils.functional import Promise - obj_dict = self.__dict__.copy() - items = [] - translated_keys = [] - for k, v in self.error_messages.items(): - if isinstance(v, Promise): - args = getattr(v, '_proxy____args', None) - if args: - translated_keys.append(k) - v = args[0] - items.append((k,v)) - obj_dict['_translated_keys'] = translated_keys - obj_dict['error_messages'] = dict(items) - return obj_dict - - def __setstate__(self, obj_dict): - """ - Unpickling support. - """ - translated_keys = obj_dict.pop('_translated_keys') - self.__dict__.update(obj_dict) - for k in translated_keys: - self.error_messages[k] = _(self.error_messages[k]) - def __cmp__(self, other): # This is needed because bisect does not take a comparison function. return cmp(self.creation_counter, other.creation_counter) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index c6723c6826..5b9a348ca3 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -88,8 +88,8 @@ class RelatedField(object): def contribute_to_class(self, cls, name): sup = super(RelatedField, self) - # Add an accessor to allow easy determination of the related query path for this field - self.related_query_name = curry(self._get_related_query_name, cls._meta) + # Store the opts for related_query_name() + self.opts = cls._meta if hasattr(sup, 'contribute_to_class'): sup.contribute_to_class(cls, name) @@ -198,12 +198,12 @@ class RelatedField(object): v = v[0] return v - def _get_related_query_name(self, opts): + def related_query_name(self): # This method defines the name that can be used to identify this # related object in a table-spanning query. It uses the lower-cased # object_name by default, but this can be overridden with the # "related_name" option. - return self.rel.related_name or opts.object_name.lower() + return self.rel.related_name or self.opts.object_name.lower() class SingleRelatedObjectDescriptor(object): # This class provides the functionality that makes the related-object |
