django - 使用 Django Simple History 创建历史记录的问题

标签 django python-3.6 django-simple-history

为什么 Django-Simple 历史记录在调用保存方法时创建,如果我调用更新然后它不创建历史记录?

Django:1.11.15 Django-简单历史:1.9.0 python :3.6

最佳答案

documentation 中所写这是一个已知问题:

Django Simple History functions by saving history using a post_save signal every time that an object with history is saved. However, for certain bulk operations, such as bulk_create and queryset updates, signals are not sent, and the history is not saved automatically. However, Django Simple History provides utility functions to work around this.

基本上,应用程序利用了您 .save() 模型这一事实,而这被一些 ORM 调用规避(因为这样您就无法执行数据库级别的“批量”操作)。

而不是使用

Entry.objects.filter(pub_date__year=2010).update(comments_on=False)

因此您需要执行:

for e in Entry.objects.filter(pub_date__year=2010):
    e.comments_on = False
    e.save()

bulk_create 有一个变体:bulk_create_with_history ,从那时起它就简单地进行了两次批量创建:一次用于对象,一次用于“历史记录”。

关于django - 使用 Django Simple History 创建历史记录的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53031661/

相关文章:

python - 如何在特定条件下获得pandas数据框的笛卡尔积

python - sessionid 的 Django (Python) 问题

django - Django REST异常(exception)

sql - 如何使用 manage.py 加载 .sql 文件

python - ZODB 中的冲突解决

带有 curses 提示的 Python 类型

python 3.5 -> 3.6 Tablib TypeError : cell() missing 1 required positional argument: 'column'

python - django-simple-history,在管理中显示更改的字段

python - 如何获取修改对象的用户? Django 简单历史

管理员中的 Django 简单历史记录