Reputation: 11049
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.
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?
Upvotes: 3
Views: 635
Reputation:
This is relatively straightforward using 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
Upvotes: 3