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)
1

There are 1 answers

1
Dave On

I'm the author of django-reversion!

Using F is not supported by django-reversion, and probably can't be. However, you can get a similar effect with reasonable efficiency like this:

with transaction.atomic(), reversion.create_revision():
    MyModel.objects.select_for_update().get(id=self.id)
    self.version = self.version + 1
    self.save()

The select_for_update() ensures the version update is atomic while retaining compatibility with django-reversion.