views:

42

answers:

1

Hi,

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

+2  A: 

You could set self.id = None in the overridden save method - 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=True parameter in the call to save, which does the same thing.

Daniel Roseman