4👍
I had a similar problem where edits made in the admin interface had reversions, but those in the shell did not.
@yilmazhuseyin is correct, you need the context wrapper, but I found I had an additional bug that my models weren’t getting registered.
In admin.py
:
class YourModelAdmin(reversion.VersionAdmin):
pass
admin.site.register(YourModel, YourModelAdmin)
will register your model, but only if the admin code is called. It wasn’t being called when I invoked the shell via python manage.py shell
So, to fix this I added to models.py
import reversion
reversion.register(YourModel)
And then when I saved an object, I still needed to use the context wrapper
with reversion.create_revision():
obj.save()
Update:
Revision has a few tips for this situation. (http://django-reversion.readthedocs.org/en/latest/api.html#api) One is to simply import your admin module so that the revision gets called.
0👍
I think you need to save model in revision transaction.
Note: If you call save() outside of the scope of a revision, a revision is NOT created. This means that you are in control of when to create revisions.
Source: http://django-reversion.readthedocs.org/en/latest/api.html#creating-revisions
- [Django]-Django, dynamic apps support
- [Django]-Can't upload image in django use MEDIA_ROOT and MEDIA_URL
- [Django]-How to send a zip file to frontend to download in DRF