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

Content type stored in logs instead of model name

This commit is contained in:
Yohann D'ANELLO 2020-02-26 23:34:27 +01:00
parent fd529a53c8
commit 1c0bf21cbe
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.core.exceptions import ValidationError
@ -20,8 +21,9 @@ class Changelog(models.Model):
verbose_name=_('user'),
)
model = models.CharField(
max_length=255,
model = models.ForeignKey(
ContentType,
on_delete=models.PROTECT,
null=False,
blank=False,
verbose_name=_('model'),

View File

@ -3,6 +3,7 @@
import inspect
from django.contrib.contenttypes.models import ContentType
from django.core import serializers
from django.db.models.signals import pre_save, pre_delete
from django.dispatch import receiver
@ -44,7 +45,7 @@ def save_object(sender, instance, **kwargs):
previous_json = None
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=previous_json,
data=instance_json,