def post_delete(sender, instance, using, **kwargs):
    """https://docs.djangoproject.com/es/1.10/ref/signals/#post-delete"""
    try:
        with transaction.atomic():
            if not should_audit(instance):
                return False

            object_json_repr = serializers.serialize("json", [instance])

            # user
            try:
                user = get_current_user()
                # validate that the user still exists
                user = get_user_model().objects.get(pk=user.pk)
            except:
                user = None

            if isinstance(user, AnonymousUser):
                user = None
            c_t = ContentType.objects.get_for_model(instance)
            sid = transaction.savepoint()
            try:
                with transaction.atomic():
                    # crud event
                    crud_event = CRUDEvent.objects.create(
                        event_type=CRUDEvent.DELETE,
                        object_repr=str(instance),
                        object_json_repr=object_json_repr,
                        content_type_id=c_t.id,
                        object_id=instance.pk,
                        user_id=getattr(user, 'id', None),
                        datetime=timezone.now(),
                        user_pk_as_string=str(user.pk) if user else user
                    )

            except Exception as e:
                logger.exception(
                    "easy audit had a pre-save exception on CRUDEvent creation. instance: {}, instance pk: {}".format(
                        instance, instance.pk))
                transaction.savepoint_rollback(sid)
    except Exception:
        logger.exception('easy audit had a post-delete exception.')
def post_delete ( sender , instance , using , ** kwargs ) : try : with transaction . atomic ( ) : if not should_audit ( instance ) : return False object_json_repr = serializers . serialize ( "json" , [ instance ] ) try : user = get_current_user ( ) user = get_user_model ( ) . objects . get ( pk = user . pk ) except : user = None if isinstance ( user , AnonymousUser ) : user = None c_t = ContentType . objects . get_for_model ( instance ) sid = transaction . savepoint ( ) try : with transaction . atomic ( ) : crud_event = CRUDEvent . objects . create ( event_type = CRUDEvent . DELETE , object_repr = str ( instance ) , object_json_repr = object_json_repr , content_type_id = c_t . id , object_id = instance . pk , user_id = getattr ( user , 'id' , None ) , datetime = timezone . now ( ) , user_pk_as_string = str ( user . pk ) if user else user ) except Exception as e : logger . exception ( "easy audit had a pre-save exception on CRUDEvent creation. instance: {}, instance pk: {}" . format ( instance , instance . pk ) ) transaction . savepoint_rollback ( sid ) except Exception : logger . exception ( 'easy audit had a post-delete exception.' )
https://docs.djangoproject.com/es/1.10/ref/signals/#post-delete