I have a model with a version field – autocreate timestamp.
When a model instance is being saved I want to create a new instance with a new timestamp instead of updating the old model instance.
Is it possible?
I thought of overriding the model save() method but I don’t know how to create a new instance without creating a infinite save() loop.
Thanks
You could set
self.id = Nonein the overriddensavemethod – then in the super method, Django would do an INSERT rather than an UPDATE.Or, as pointed out in the documentation here, you could use the
force_insert=Trueparameter in the call tosave, which does the same thing.