<

<

<
from uuid import uuid4
from django.db import models
from simple_history.models import HistoricalRecords


class BaseModel(models.Model):
    class Meta:
        abstract = True

    history = HistoricalRecords(inherit=True)

    id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
    created_at = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, blank=True, auto_now=True)

<

models.py

class TestModel(BaseModel):
    text = models.CharField(max_length=100)
    un = models.IntegerField()
    new_text = models.CharField(max_length=100)

<

<
from modeltranslation.translator import register, TranslationOptions
from test_app.models import TestDeleteModel


@register(TestModel)
class TestModelTranslationOptions(TranslationOptions):
    fields = (
        'text',
        'new_text',
    )

<

<

<
from modeltranslation.translator import register, TranslationOptions
import simple_history
from test_app.models import TestDeleteModel


@register(TestDeleteModel)
class TestDeleteModelTranslationOptions(TranslationOptions):
    fields = (
        'text',
        'new_text',
    )

simple_history.register(TestDeleteModel)

Однако это привело к ошибке simple_history.exceptions.MultipleRegistrationsError с сообщением "TestModel зарегистрирована несколько раз для отслеживания истории."

<
Вернуться на верх