[Answered ]-How to access comments and user from django reversion object

2👍

✅

Check the revision attribute of the Version object. Notice that the usual way to get a list of Versions for a specific object obj is to use the reversion.get_for_object(obj) method.

Also, I’ve written a rather comprehensive Post about reversion (and other similar solutions) @ http://spapas.github.io/2015/01/21/django-model-auditing/

0👍

Create a function in your views as below

from reversion.models import Version
import json

def history_list(request)
 history_list = Version.objects.all().oreder_by('revision_date_created')
 data = []
 for i in history_list:
  data.append({
     'user': str(i.revision.user),
     'comment': i.revision.comment
  })
print(data)

Instead of printing in your terminal if you would like to have a route where it should print user and comment as json add the additional to above function

from django.http import HttpRespose
...............
...............
data_ser = json.dumps(data)
return HttpResponse(data_ser, content_type="application/json")

Leave a comment