Django - how do I clone object without applying clone changes to source object
<p>Best described by example:</p>

<p>View:</p>

<pre><code>def my_view(request):
    obj_old = Inventories.objects.get(id = source_id)
    obj_new = obj_old 
    obj_old.some_field = 0
    obj_old.save()

    obj_new.some_field = 1
    obj_new.id = None
    obj_new.save()
</code></pre>

<p>The problem is that the changes I make to obj_new are also applied to <code>obj_old</code> so that the value of <code>some_field</code> is 1 for both <code>obj_old</code> and <code>obj_new</code>. Any ideas how to fix this ?</p>

<p>You should make a <em>copy</em> of your object, and not make them equal.  </p>

<p>To make a copy you can use the copy module</p>

<pre><code>import copy

obj_new = copy.deepcopy(obj_old)
</code></pre>

python django