admin管理员组文章数量:1404351
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.
本文标签: djangoHow can I prevent HistoricalModel Creation When Inheriting from Abstract ModelStack Overflow
版权声明:本文标题:django - How can I prevent HistoricalModel Creation When Inheriting from Abstract Model? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744790299a2625245.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论