I want to clone a django model/object. Here is my code with some debugging statements (method is inside my Item class)
def duplicate_item(self):
print("original",self.id)
copy = self
copy.id = uuid.uuid4()
print("copy",copy.id)
copy.save()
print("What happened",self.id)
This was the output:
original 6a5a8d54-5b45-47fd-abf3-4357aa89dd0c
copy 5b6bfb5f-36b2-4a74-968e-c1f007df9056
what happened 5b6bfb5f-36b2-4a74-968e-c1f007df9056
Why does this happen? I don't know enough about python shallow/deep copy logic so that probably has to do with it. Thank you