How to add django-reversion to an app developed using django and django-rest framework

拟墨画扇 提交于 2019-12-01 05:20:03

The simplest way to create revisions is to use reversion.middleware.RevisionMiddleware. This will automatically wrap every request in a revision, ensuring that all changes to your models will be added to their version history.

To enable the revision middleware, simply add it to your MIDDLEWARE_CLASSES setting as follows:

MIDDLEWARE_CLASSES = (
    'reversion.middleware.RevisionMiddleware',
    # Other middleware goes here...
)

Any thing more complex with this will require adding API calls through your code in away that wraps specific save calls in ways that you decide.

admin.py

from django.contrib import admin
from.models import Category
import reversion

class BaseReversionAdmin(reversion.VersionAdmin):
 pass

admin.site.register(Category, BaseReversionAdmin)

also added reversion to installed_apps and middlewareclasses.

Finally i could see the "recover deleted objects button".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!