django-reversion-compare icon indicating copy to clipboard operation
django-reversion-compare copied to clipboard

Documentation doesn't cover how to progamatically compare versions

Open ptav opened this issue 7 years ago • 3 comments

The current documentation explains how to integrate with Django admin but doesn't cover the use case where two versions need to be compared inside the code (e.g. producing a report of changes). thank you

ptav avatar Aug 05 '18 18:08 ptav

@ptav Did you have any success doing this? I'm trying to figure out how to integrate this into a REST interface ... but the docs seem to be very View or Admin specific.

rrauenza avatar Jan 17 '19 16:01 rrauenza

Here's what I have gotten so far:

In [8]: from reversion_compare.mixins import CompareMixin

In [10]: CompareMixin().compare(Version.objects.all()[0].object, Version.objects.all()[0], rm.Version.objects.all()[1])

Out[10]: 
([{'diff': u'<span>2018-08-28 17:10:</span><del style="background:#ffe6e6;">40.928</del><ins style="background:#e6ffe6;">02.932</ins><span>000+00:00</span>',
   'field': <django.db.models.fields.DateTimeField: last_login>,
   'follow': None,
   'is_related': False}],
 True)

rrauenza avatar Jan 17 '19 17:01 rrauenza

but the docs seem to be very View or Admin specific

The original goal was only the admin site ;)

I think the best thing to do is look here:

  • https://github.com/jedie/django-reversion-compare/blob/master/reversion_compare/views.py
  • https://github.com/jedie/django-reversion-compare/blob/master/reversion_compare/mixins.py

Think it makes sense to move the "main" code from mixins.py to a better place, where it's useable in other situations, too (e.g.: REST-API sterilizer...)

Pull requests are welcome ;)

jedie avatar Jan 18 '19 07:01 jedie