Исключите django-simple-history из дочерней модели
Я застрял в проблеме, когда мне нужно исключить HistoricalRecords (django-simple-history) из дочернего класса без внесения изменений в родительский класс.
Вот мой код выглядит так
from simple_history.models import HistoricalRecords
class BaseModel(models.Model):
id = models.UUIDField(...some args...)
created_at = models.DateTimeField(...some args...)
created_by = models.ForeignKey(...some args...)
history = HistoricalRecords(inherit=True)
class Meta:
abstract = True
default_permissions = Constants.STANDARD_ACTIONS
def save(self, suppress_modified=False, from_publish=False, **kwargs):
super(BaseModel, self).save(**kwargs)
class CommonWithExtraFieldsWithoutVersioning(BaseModel, CommonWithoutVersioning, models.Model):
class Meta(CommonWithoutVersioning.Meta):
abstract = True
class Manager(CommonWithExtraFieldsWithoutVersioning):
from_branch = models.CharField(...some args...)
to_branch = models.CharField(...some args...)
from_version = models.IntegerField(...some args...)
to_version = models.IntegerField(...some args...)
history = None # this is also not working for me
def __init__(self, *args, **kwargs): # this I have tried but not working
super(DSLJourneyMergeHistory, self).__init__(*args, **kwargs)
self.clean_fields('history')
Но когда я пытаюсь makemigration
, он создает HistoricalRecords и для менеджера, а я хочу, чтобы HistoricalRecords
не сохранялись для class manager
. Как мне исключить это, поскольку модели BaseModel и CommonWithExtraFields используются во всем приложении, и я не могу вносить какие-либо изменения в эту модель