django-reversion撤销功能 - 恢复多个对象 [英] django-reversion undo feature - recovering multiple objects

查看:182
本文介绍了django-reversion撤销功能 - 恢复多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在django项目中,我尝试使用django-reversion实现撤消功能,当用户意外修改多个对象时。使用管理面板将无法正常工作,因为必须逐个还原对象。

I'm trying to implement 'undo' feature in django project with django-reversion in a case when user can accidentally modify multiple objects. Using admin panel won't work as one has to revert objects one-by-one.

我的问题是我无法创建修改,一个对象。

即使我做了

My problem is that I am unable to create revision that holds data about more than one object.
Even when I do

with reversion.create_revision():
    Res.object.all().delete()

然后我无法访问修改组对此更改。它分为一个对象一个revision.models.Version方式。

then I cannot access revision that groups this change. It's splitted in a "one object one revision.models.Version" manner.

In [103]: reversion.models.Version.objects.all()
Out[103]: [<Version: #00001>, <Version: #00002>]

我也尝试过

reversion.models.Revision.objects.all().order_by('-date_created')[0].version_set.all()

但它也只为一个已删除的Res对象返回一个版本。
好​​像我错过了一些东西。

but it also returned only one Version for one deleted Res object. Seems like I'm missing something.

推荐答案

我终于找到了。

问题1:在单个版本中存储与多个对象相关的更改

Issue 1: Store changes related to multiple objects in a single Revision

解决方案:将TransactionMiddleware添加到MIDDLEWARE_CLASSES

Solution: add TransactionMiddleware to MIDDLEWARE_CLASSES

问题2:撤消功能/恢复更改

REVERT CHANGES ,您可以将 RESTORE OBJECT 更改为先前已知的状态。在对象更改视图中使用reversion.create_revision()在更改之后存储关于该对象的数据。如果您有修改多个对象的视图,则必须在 之前创建修订 进行实际更改。

Well, this is confusing. You cannot REVERT CHANGES you can RESTORE OBJECT to previously known state. And using reversion.create_revision() in your object-altering views stores data about that object after changing it. If you have view that modify multiple object then you have to create revision before making actual changes.

这也在管理面板中显示。如果您更改对象,则将显示新日志条目。但是,如果您想要恢复该更改,您无法选择最新版本 - 它与对象的当前状态相同 - 您必须选择以前的

This is also visible in admin panel. If you change your object than a new log entry will appear. But if you want to revert that change than you cannot select newest version -- it is identical with the current state of the object -- instead you have to choose the previous one.

这篇关于django-reversion撤销功能 - 恢复多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆