[Answered ]-Split the revision.comment into field and value in Django-reversion

1👍

✅

I hope I understood the problem properly, here’s the half baked solution to it:

from django.db.models.signals import pre_save
from django.dispatch import receiver
import reversion

@receiver(pre_save)
def _pre_save(sender, **kwargs):
    _i = kwargs.get('instance')
    _i_old = sender.objects.get(pk=_i.pk)
    _current, _past = set(_i.__dict__.keys()), set(_i_old.__dict__.keys())
    _intersection = _current.intersection(_past)
    _changed_keys = set(o for o in _intersection if _i.__dict__[o] != _i_old.__dict__[o])
    _comment = ['changed {} from {} to {}'.format(_, _i_old.__dict__[_], _i.__dict__[_]) for _ in _changed_keys]
    reversion.set_comment(', '.join(_comment))

Haven’t thought much about the performance overhead, but this should do the trick.

Hope this helps.

1👍

I think that if you save the ver.field_dict of the actual and the previous (the same place where you make the version commit), compare then and save the version changes in another Model you can achieve what you want.

history_list = Version.objects.all().order_by('-revision__date_created')
ver = history_list[0]
ver.field_dict

Maybe this app can help you.
https://github.com/jedie/django-reversion-compare

Leave a comment