Created
October 7, 2016 00:20
-
-
Save ericvoid/5a63caf55318eb2f8dcd0372bd0c6366 to your computer and use it in GitHub Desktop.
Django Object Clone
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
from django.db import models | |
class djobjclone(object): | |
""" | |
Makes a clone of a django model object. | |
The clone is shallow and handicapped. | |
""" | |
def __init__(self, o): | |
assert isinstance(o, models.Model) | |
ns = [f.attname for f in o._meta.get_fields() if f.concrete] | |
for n in ns: | |
setattr(self, n, getattr(o, n)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment