Last active
December 25, 2015 17:19
-
-
Save ondrowan/7012154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
class FieldTracker(object): | |
def patch_save(self, instance): | |
original_save = instance.save | |
def save(**kwargs): | |
ret = original_save(**kwargs) | |
# use properties of self, implement new stuff etc | |
print 'Used patched save' | |
return ret | |
instance.save = save | |
class Model(object): | |
name_field = 'joe' | |
field_tracker = FieldTracker() | |
def __init__(self): | |
self.field_tracker.patch_save(self) | |
def save(self): | |
print 'Used default save' | |
model = Model() | |
model.save() # Uses patched version of save | |
pickle.dumps(model) # Fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment