@ -1,5 +1,6 @@
|
||||
from django.apps import apps
|
||||
from django.contrib.auth.models import ContentType
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models.signals import (
|
||||
# post_delete,
|
||||
post_save
|
||||
@ -26,6 +27,14 @@ def audit_history(sender, instance, **kwargs):
|
||||
|
||||
audit_action = audit_model.Actions.DELETE
|
||||
|
||||
if instance.context.get('user', None) is None:
|
||||
|
||||
raise ValidationError(
|
||||
code = 'model_missing_user_context',
|
||||
message = f'Model {instance._meta.model_name}, is missing user context. ' \
|
||||
'No audit history can be saved'
|
||||
)
|
||||
|
||||
|
||||
history = audit_model.objects.create(
|
||||
organization = instance.organization,
|
||||
|
Reference in New Issue
Block a user