4

Using: django 1.10 reversion 2.0.8.

My question is how to show a nice list of changes done to a given model instance. By that I mean that the user can quickly see a list of all the changes (new values for fields) in all revisions. He doesn't need o see all the fields only the new values of the changed ones.

So I found that a good tool for storing changes is django-reversion. However, I cannot find a solution for my problem which as I mentioned is to show a nice change-log history for a given model instance.

I found solution that can compare two revisions django-reversion-compare, but that is not what I am looking for. Maybe there is a better tool for that ?

The task is too quickly show to user what was changed by who and when. The model is simple and doesn't store a lot of data. It does store however foreign keys.

CodeSamurai777
  • 3,285
  • 2
  • 24
  • 42

1 Answers1

1

I was also looking to do the same, and after reading up a few SO posts, docs etc., it seems I had to roughly choose the solution from one of the following 3 approaches:

1) Fetch the existing model instance before saving the new model instance. Compare each field. Put the changed field in reversion.set_comment('(all changes here)'). Continue with saving the model instance.

2) Save a copy of the old fields separately in model's __init__() and later compare the new fields with them (in model's save()) to track what changed. Put the changed fields in reversion.set_comment('(all changes here)'). Continue with saving the model instance. (This approach will save a DB lookup)

3) Generate a diff using django-reversion's low-level API and integrate with the Admin somehow

I ended up using django-reversion-compare which worked great for me showing the edits wiki-style (which may be using (3) above anyways)

django-reversion's developer also confirmed (3) as a better option which also avoids race condition.

If you would like to explore different options, this is a great SO post with lots of good ideas with their pros/cons.

(I am also on Django 1.10)

Anupam
  • 14,950
  • 19
  • 67
  • 94