0

如何将 django-simple-history 中的查询集解析为包含以下列的 html 表:history_id、history_date 等。我继承了 DetailView 类

4

1 回答 1

0

示例形式 django-simple-history:

from django.db import models
from simple_history.models import HistoricalRecords

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    history = HistoricalRecords()

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
    history = HistoricalRecords()

现在您可以通过以下方式访问历史记录:

all_history = poll.history.all()

更多信息 :

  1. https://django-simple-history.readthedocs.io/en/latest/querying_history.html
  2. https://django-simple-history.readthedocs.io/en/latest/quick_start.html
于 2021-03-18T09:43:16.390 回答