Last active
August 3, 2016 13:56
-
-
Save kezabelle/b6a7070bbd4a2edc6ef43334eb2a04e8 to your computer and use it in GitHub Desktop.
for tga in #django IRC.
This file contains hidden or 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
@contextmanager | |
def copyable(obj): | |
oldval = copy(obj.pk) | |
obj.pk = None | |
yield obj | |
obj.pk = oldval | |
with copyable(obj) as tosave: # I might've forgotten the as part initially. | |
newobj = tosave.save() | |
print(obj.pk) | |
print(newobj.pk) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment