特定のフィールドにインデックスを付けるように DSH に指示するにはどうすればよいですか? 履歴モデルに対して実行する一部のクエリには時間がかかりすぎます
基本抽象モデルがあり、すべてのモデルはそのモデルを継承しています。history フィールドもこの基本モデルで定義されています。
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の単純な履歴に明示的に伝える方法がありますか?