我正在使用 django-simple-history 保存 django 模型中每次更改的更改历史记录。
那是我尝试过的:
class MyModel(models.models):
field1 = ...
...
history = HistoricalRecords(
history_change_reason_field=models.TextField(null=True)
)
name = 'xyz'
for doc_id, status in my_data:
reporting , _ = MyModel.objects.get_or_create(
doc_id=doc_id,
user=self.request.user
)
reporting.is_accepted = status
reporting.save(
update_fields=['is_accepted']
)
update_change_reason(
instance=reporting,
reason=f'Change request done by {name}'
)
我得到了以下错误。
AttributeError: 'NoneType' object has no attribute 'history_change_reason'