我正在尝试使用django-simple-history来保持对象的状态。
假设我有以下内容:
class Parent(models.Model):
fields...
history = HistoricalRecords(inherit=True)
class Child(Parent):
fields...
class Invoice(models.Model):
fields...
parent_history = models.ForeignKey("app.HistoricalParent", blank=True, null=True, on_delete=models.PROTECT, help_text="This keeps the state of the Child when Invoice is generated")
parent = models.ForeignKey(Parent, blank=True, null=True, on_delete=models.PROTECT) # can be removed so foreign key loop gets eliminated
我怎样才能到达从Invoice
到Child
?
Invoice.objects.get(id=1).parent_history.child
不工作和提高
AttributeError: 'HistoricalParent' object has no attribute 'child'
这就是我Child
从Parent
Invoice.objects.get(id=1).parent.child
我找不到 to 的外HistoricalChild
键HistoricalParent
。我错过了什么吗?django-simple-history 是否以其他方式工作?