Reputation: 129
Let's say I want to create a version of an object only in certain conditions, for example when 'status' field of object of class 'mymodel' is being changed to 'submitted'. How can I do this?
class MyModel(AbstractModel):
number = models.CharField(max_length=255)
status = models.CharField(max_length=32)
def save(self, *args, **kwargs) -> bool:
if self.status == 'submitted':
#TODO: create version. HOW??????
return super().save(*args, **kwargs)
Also how can I suppress automatic version creation on every save?
Upvotes: 0
Views: 224
Reputation: 129
Found a way:
with reversion.create_revision(manage_manually=True, atomic=False):
reversion.add_to_revision(self)
self.save()
Upvotes: 0