Skip to content

Instantly share code, notes, and snippets.

@ericvoid
Created October 7, 2016 00:20
Show Gist options
  • Save ericvoid/5a63caf55318eb2f8dcd0372bd0c6366 to your computer and use it in GitHub Desktop.
Save ericvoid/5a63caf55318eb2f8dcd0372bd0c6366 to your computer and use it in GitHub Desktop.
Django Object Clone
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