简体   繁体   English

从django-reversion获取版本ID

[英]Getting revision id from django-reversion

I am trying to get the reversion id on the history page. 我正在尝试在历史记录页面上获取版本ID。

On my history page, there are links like: 在我的历史记录页面上,有如下链接:

6 May 2015, 3:11 p.m.   root    Initial version.
6 May 2015, 3:36 p.m.   root    Changed description.

The links are respectively: 链接分别是:

http://127.0.0.1:8000/admin/app/model/103051/history/4672/
http://127.0.0.1:8000/admin/app/model/103051/history/4674/

How can I access the revision id (4674 or 4672)? 如何访问修订版ID(4674或4672)? The closest I can get is: 我能得到的最接近的是:

>>import reversion
>>model_history = reversion.get_for_object(model_instance)
[<Version: Model103051>, <Version: Model103051>]
>>model_history[0].id
4673L
>>model_history[1].id
4671L

As you can see, the numbers are off by one. 如您所见,数字相减一。 I know these are the correct versions, because when I do a model_history[0].revision.comment and model_history[0].revision.date_created match up with the history page. 我知道这些是正确的版本,因为当我执行model_history[0].revision.commentmodel_history[0].revision.date_created时,它们会与历史记录页面匹配。

Is it safe for me to simply take the id and add 1 to get the revision used by django-reversion? 对我来说,简单地获取id并加1以获得django-reversion使用的修订版安全吗?

I think it has to do with the duplication while saving. 我认为这与保存时的重复有关。 and garbage collection afterwards. 和垃圾收集。 So some versions in between are deleted later in case duplicate, read the discussion in this issue: https://github.com/etianen/django-reversion/issues/378 因此,稍后之间的某些版本会被删除(以防万一),请阅读本期的讨论: https : //github.com/etianen/django-reversion/issues/378

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM