summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNerl~ <nerlin57@gmail.com>2017-08-11 22:27:25 +0300
committerTim Graham <timograham@gmail.com>2017-08-11 15:27:25 -0400
commit97cb3bd16d8e50d96eb184f8d67dd1723f776d2a (patch)
treeaa4574295bf1eeee681402531bdcbdb582289fb6 /django
parent31f133ea08d41907a67f9e3d667f2a09c167a97c (diff)
Fixed #28456 -- Allowed customizing Model pickling by overriding __getstate__().
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index dda2248308..3cff2d2fc4 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -522,11 +522,15 @@ class Model(metaclass=ModelBase):
return hash(self.pk)
def __reduce__(self):
- data = self.__dict__
+ data = self.__getstate__()
data[DJANGO_VERSION_PICKLE_KEY] = get_version()
class_id = self._meta.app_label, self._meta.object_name
return model_unpickle, (class_id,), data
+ def __getstate__(self):
+ """Hook to allow choosing the attributes to pickle."""
+ return self.__dict__
+
def __setstate__(self, state):
msg = None
pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)