django - How can I prevent HistoricalModel Creation When Inheriting from Abstract Model? - Stack Overflow

I have an abstract base model, CompanyAwareModel, which includes historical tracking using TenantHistor

I have an abstract base model, CompanyAwareModel, which includes historical tracking using TenantHistoricalRecords:

class CompanyAwareModel(RequestChangeReasonModelMixin, TenantModel, TimeStampedModel, metaclass=CompanyAwareMeta):

    tenant_id = 'company_id'
    company = models.ForeignKey(Company, on_delete=models.CASCADE)
    history = TenantHistoricalRecords(inherit=True)
    class Meta:
        abstract = True

To create a variant of this model without historical tracking, I defined another abstract model:

class NoHistoryCompanyAwareModel(CompanyAwareModel):
    history = None

    class Meta:
        abstract = True

Then, I define a concrete model inheriting from NoHistoryCompanyAwareModel:

class Counter(NoHistoryCompanyAwareModel):
    ...

However, when I run makemigrations, Django still creates a HistoricalCounter model, even though I explicitly set history = None in NoHistoryCompanyAwareModel.

Interestingly, if I define NoHistoryCompanyAwareModel without inheriting from CompanyAwareModel, like this:

class NoHistoryCompanyAwareModel(RequestChangeReasonModelMixin, TenantModel, TimeStampedModel, metaclass=CompanyAwareMeta):
    tenant_id = 'company_id'
    company = models.ForeignKey(Company, on_delete=models.CASCADE)

    history = None

    class Meta:
        abstract = True

Then makemigrations does not create a historical table for Counter.

Question

Why does inheriting from CompanyAwareModel still create a historical table, even when history = None is explicitly set? And how can I ensure that Counter does not have a HistoricalCounter model while still inheriting from CompanyAwareModel?

I expect that when I inherit the NoHistoryComapnyAwareModel from the CompanyAawreModel and set the history to None it won't create a historicalCounter for my model.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744790299a4593872.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信