update_nb_version.py 460 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from reversion.models import Version
from django.db.models.signals import post_delete


def update_nb_version_on_version_delete(sender, instance, **kwargs):
    pk = instance.object_id
    ct = instance.content_type

    obj = ct.get_object_for_this_type(pk=pk)
    # Make sure we have a new coherent value
    obj.nb_versions = len(Version.objects.get_for_object(obj))
    obj.save()


post_delete.connect(update_nb_version_on_version_delete, sender=Version)