1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-27 09:52:22 +00:00

Update some excluded models

This commit is contained in:
Yohann D'ANELLO 2020-02-26 23:55:40 +01:00
parent 1c0bf21cbe
commit 10854eb334

View File

@ -25,15 +25,17 @@ def get_user_in_signal(sender, **kwargs):
return user
EXCLUDED = [
'Changelog',
'Migration',
'Session',
'changelog',
'migration',
'revision',
'session',
'version',
]
@receiver(pre_save)
def save_object(sender, instance, **kwargs):
model_name = sender.__name__
if model_name in EXCLUDED:
if model_name.lower() in EXCLUDED:
return
previous = sender.objects.filter(pk=instance.pk).all()
@ -55,13 +57,13 @@ def save_object(sender, instance, **kwargs):
@receiver(pre_delete)
def delete_object(sender, instance, **kwargs):
model_name = sender.__name__
if model_name in EXCLUDED:
if model_name.lower() in EXCLUDED:
return
user = get_user_in_signal(sender, **kwargs)
instance_json = serializers.serialize('json', [instance, ])[1:-1]
Changelog.objects.create(user=user,
model=model_name,
model=ContentType.objects.get_for_model(instance),
instance_pk=instance.pk,
previous=instance_json,
data=None,