python - 如何为 django 简单历史表设置 manage=False
问题描述
我正在使用django-simple-history
我的模型。我正在删除模型上的一个字段,但将meta
属性设置managed
为False
. 然而,这并不能转化为简单的历史表。有没有办法做到这一点?
解决方案
您可以子类化HistoricalRecords
该类,并覆盖该get_meta_options
函数。例如:
from simple_history.models import HistoricalRecords
class UnmanagedHistoricalRecords(HistoricalRecords):
def get_meta_options(self, model):
result = super().get_meta_options(model)
result['managed'] = False
return result
然后我们可以UnmanagedHistoricalRecords
在我们的模型中使用我们的类:
class SomeModel(models.Model):
# …
objects = UnmanagedHistoricalRecords()
因此,我们将在此处将 a 传递managed = False
给将由UnmanagedHistoricalRecords
对象管理器构造的模型。
推荐阅读
- graphql - graphql - 解析器根/父属性为空
- php - 动态调用php对象属性
- php - 在这个模型中我需要做什么关系?
- google-cloud-dataflow - Google Dataflow - Wall Time/PCollection 输出数字倒退
- c# - 为什么 WMI 通过搜索而不是直接工作?
- javascript - 确定日期字段是 NaN 还是空
- scroll - 如何仅在用户滚动时显示小部件?
- sqlite - 给定 ID 的最后一个 MAX 报告值
- facebook - FIREBASE 我可以为使用 facebook 或 google 创建的帐户设置密码吗?
- google-apps-script - 将 =IFS 语句转换为 Google 表格中的脚本