djangosnippets.org: Latest snippets tagged with 'clonable'https://djangosnippets.org/tags/clonable/2008-12-31T02:55:06.661285-06:00Clone model mixin
2008-12-31T02:55:06.661285-06:00zakjhttps://djangosnippets.org/snippets/1271/<p>Add this as a superclass of any Django model to allow making copies of instances of that model:</p>
<pre><code>class Entry(models.Model, CloneableMixin):
[...]
e = Entry.objects.get(...)
e_clone = e.clone()
e_clone.title = 'Cloned Entry'
e.save()
</code></pre>
<p>The new object is saved during the clone process and ManyToMany relations are copied as well.</p>
Freely redistributable