简体   繁体   English

django-reversion的修改日期

[英]Modification date from django-reversion

I used to have two date fields to save the date an object is created and modified and two foreign key fields to save who created or last modified the object. 我曾经有两个日期字段来保存创建和修改对象的日期,以及两个外键字段来保存创建或最后修改对象的人。

Now I'm using django-reversion and I'm able to save all the users who modified the object instead of only the last person. 现在我正在使用django-reversion ,我能够保存修改对象的所有用户,而不仅仅是最后一个人。

But how can I print the date the object was created and last modified using django-reversion instead of storing these information in the object itself? 但是如何使用django-reversion打印对象创建和最后修改的日期,而不是将这些信息存储在对象本身中?

This is relatively straightforward using get_for_object_reference : 使用get_for_object_reference这是相对简单的:

from reversion.revisions import default_revision_manager
item = MyModel.objects.get(some_criteria=True)
last_edit = default_revision_manager.get_for_object_reference(
        item.__class__,
        item.pk,
    ).first()

last_editor = last_edit.revision.user
date_edited = last_edit.revision.date_created

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

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