Permalink
Browse files

Can now pickle models (manager will not be pickled)

  • Loading branch information...
1 parent e441aef commit 66714283ec7ef3e2daccc11493df7d59feecbfff Ask Solem committed Nov 3, 2010
Showing with 7 additions and 1 deletion.
  1. +7 −1 redish/models.py
View
@@ -13,6 +13,9 @@ def __new__(cls, name, bases, attrs):
return super(ModelType, cls).__new__(cls, name, bases, attrs)
+def _unpickle_model(model, id, fields):
+ return model(id=id, **fields)
+
class Model(dict):
"""A Model.
@@ -48,11 +51,14 @@ class Model(dict):
name = None
objects = None
- def __init__(self, manager, id=None, **fields):
+ def __init__(self, manager=None, id=None, **fields):
self.objects = manager
self.id = id
dict.__init__(self, self.prepare_fields(fields))
+ def __reduce__(self):
+ return (_unpickle_model, (self.__class__, id, fields), None)
+
def save(self):
"""Save this entry.

0 comments on commit 6671428

Please sign in to comment.