【发布时间】:2020-10-14 18:18:48
【问题描述】:
如何告诉 DSH 索引特定字段?我对历史模型进行的一些查询花费了太多时间
我有基本的抽象模型,我的所有模型都继承自该模型。这个基本模型中也定义了历史字段:
class BaseModel(models.Model):
class PublishingStatus(models.TextChoices):
DRAFT = 'draft', _('Draft')
ACCEPTED = 'accepted', _('Accepted'),
REJECTED = 'rejected', _('Rejected'),
MODIFIED = 'modified', _('Modified')
publishing_status = models.CharField(
max_length=9,
choices=PublishingStatus.choices,
default=PublishingStatus.DRAFT,
help_text=_("Publishing status represents the state of the object. By default it is 'draft'")
)
history = HistoricalRecords(inherit=True)
我还在这个基本模型中添加了索引
class Meta:
abstract = True
indexes = [models.Index(fields=[
'publishing_status',
])]
如果 Django Simple History 可以检查哪些字段被索引并在历史模型中创建相同的索引,那就太好了
也许有一种方法可以明确地告诉 django 简单历史必须另外索引哪个字段?
【问题讨论】:
标签: django django-simple-history