在Djang中向我的模型添加历史视图

2024-09-27 00:12:18 发布

您现在位置:Python中文网/ 问答频道 /正文

当我更改Django模型时,如何在管理中添加历史记录?,当我保存到其他模板或shell中时

我在管理中使用Django1.6。更改被存储,但在另一个模板中我看不到这些更改。我怎样才能解决这个问题?在

class Modelo(models.Model):
    nombre = models.CharField(max_length=100)
    marca = models.ForeignKey(Marca)
    def __unicode__(self):
        return self.nombre
    class Meta:
        unique_together = ("nombre", "marca")
        verbose_name_plural = u'Modelos'
        verbose_name=u'Modelos'

Tags: djangoname模型self模板verbose历史记录model
1条回答
网友
1楼 · 发布于 2024-09-27 00:12:18

您可以使用django-simple-history应用程序

一些简单用法(在配置应用程序后,从文档中):

>>> from polls.models import Poll, Choice
>>> from datetime import datetime
>>> poll = Poll.objects.create(question="what's up?", pub_date=datetime.now())
>>>
>>> poll.history.all()
[<HistoricalPoll: Poll object as of 2010-10-25 18:03:29.855689>]

相关问题 更多 >

    热门问题