django-reversion-compare
django-reversion-compare copied to clipboard
Documentation doesn't cover how to progamatically compare versions
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 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.
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)
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 ;)