I am trying to use reversions to get keep the revisions of my model, but my model has a field that is updated like this self.version = F("version") + 1
.
Now if I use the below code, I am getting this error django.core.serializers.base.DeserializationError: ['“F(version) + Value(1)” value must be an integer.']
with transaction.atomic(), reversion.create_revision():
self.save()
reversion.set_user(user)
but if I use this code, the revision is working fine, but I think this is quite inefficient, is there any other way to do this??
self.save()
with transaction.atomic(), reversion.create_revision():
self.refresh_from_db()
self.save()
reversion.set_user(user)
I'm the author of
django-reversion
!Using
F
is not supported bydjango-reversion
, and probably can't be. However, you can get a similar effect with reasonable efficiency like this:The
select_for_update()
ensures the version update is atomic while retaining compatibility withdjango-reversion
.