Reputation: 3285
I want to be able to store objects in my database with a version. So whenever there is a change to the object, a new object is created with a higher version. This allows objects from other models still using the older version of the object.
I don't want versioning for my modesl, but for my objects.
Example: Let's say for a webshop one model is the item the other is the order. If some customer places an order he of course wants to buy exactly the item that he saw when placing the order. But if the item changes price this should not have any influence on the already placed orders but only on the future orders.
Upvotes: 1
Views: 408
Reputation: 2769
I don't think it would be a practical solution to a webshop example as you only need certain data to remain frozen and it's generally more practical to just copy the name, SKU and price to the ordered item model. You most likely don't need to freeze stuff like stock levels, detailed descriptions or images.
However since you're asking in general, you might want to take a look at:
http://www.djangopackages.com/grids/g/versioning/
Upvotes: 1
Reputation: 5249
Basically if you want to create new object each time you call save
, just clear it's pk.
class PersistentModel(models.Model)
def save(self):
if self.pk is not None:
self.pk = None
return super(PersistentModel, self).save()
Upvotes: 0