- July 22, 2008
- django models clone
- 0 (after 0 ratings)
Add this method to any model to make it clonable.
1 2 3
def clone(self): new_kwargs = dict([(fld.name, getattr(old, fld.name)) for fld in old._meta.fields if fld.name != 'id']); return self.__class__.objects.create(**new_kwargs)