问题标签 [django-simple-history]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
733 浏览

python - django-simple-history save_without_historical_record 不起作用

以下是我的 django 模型横幅:

访问上述模型的鼻子测试用例:

工厂 :

执行此测试用例时,它不会在没有历史记录的情况下保存,因为它需要一个 User 实例。

完整的追溯:

问题似乎出在 simple_history/models.py 中的 post_save 函数中。created 标志被发送 True 反过来不会使第一个条件返回。

这个创建的标志是从 django 模型脚本设置的:

不确定要做什么。

0 投票
0 回答
444 浏览

python - Django-simple-history 错误设置 ChangeReason

我将 Django-simple-history 版本 2.3.0 与 Django 2.0 和 Python 3.6 一起使用。

我正在将先前存在的数据与通过 PUT 请求接收的新数据(与 serializer.validated_data 相比)进行比较,比较字段并制作更改列表。

我正在尝试将此列表添加到我的 changeReason 中。

我第一次尝试保存序列化程序然后调用更新导致数据库中有 2 个条目。

我尝试遵循文档并按照那里的建议进行设置,但出现以下错误:

当我尝试使用 update_change_reason 显式传递 changeReason

或者

当我隐式尝试时。

我的问题:

如何更新 changeReason 并且在数据库中也只有 1 个条目。

这是我的视图代码:

我尝试先执行 serializer.save(),然后调用对象并更新 changeReason,但这会导致模型的简单历史记录表中有 2 个条目。我如何只用 1 个条目来做到这一点。

我的序列化器:

谢谢。

PS:这是我的第一篇文章,如果我遗漏了任何信息或提供的信息不完整,请告诉我,我会相应地更新。

0 投票
0 回答
177 浏览

django - 如何在 Django 中为历史表设置自动生成的元字段

样品模型

在上面的模型中,我使用了HistoricalRecordsfrom django-simple-history来保存每个实例的更改历史Sample

问题

history_user无法填充错误消息:**Error** : 1452, 'Cannot add or update a child row: a foreign key constraint fails,REFERENCES auth_user (id)

如何在实例中设置history_change_reasonand ?history_user_idHistoricalRecords()

编辑:尝试过这个解决方案:链接

0 投票
1 回答
917 浏览

django - 使用 Django 简单历史创建历史记录的问题

为什么 Django-Simple 历史记录会在调用 save 方法时创建,如果我调用 update 然后它不会创建历史记录?

Django:1.11.15 Django-simple-history:1.9.0 Python:3.6

0 投票
1 回答
69 浏览

django-simple-history - django-simple-history 1.9 中断单元测试

当我使用 django-simple-history==1.6.0 运行单元测试时,它运行良好,但是使用 django-simple-history==1.9.0 它会破坏单元测试。任何想法如何解决这一问题?

0 投票
2 回答
1413 浏览

django-simple-history - 无法设置/读取 Django 简单历史更改原因

我正在使用 Django 的 simple_history 包,并想记录用户是否创建、更新或删除模型对象。我以为我会为此目的使用历史更改原因,并在 models.py 中执行类似的操作

当我保存模型时,这个“changeReason”字段似乎已设置(至少没有错误),但是当我尝试在 .history.first().instance.changeReason 之类的测试用例中读取它时,它抱怨该字段“ changeReason' 不存在。history.first() 调用有效,所以我确实有历史记录。

我在 settings.py 中有 SIMPLE_HISTORY_HISTORY_CHANGE_REASON_USE_TEXT_FIELD = True

我可能忽略了一些基本的东西,但我似乎无法弄清楚是什么......

谢谢,

0 投票
1 回答
1086 浏览

python - Django-simple-history 如何将额外的信息/对象附加到历史记录?

我正在寻找一种方法来更改历史记录中的额外字段。

我有一个模型InvoiceBalance.

每次Invoice创建对象时,都会对其UserBalance.balance进行修改并自动创建历史记录。

我想将此Invoice对象添加到历史记录中,但它不起作用。invoice_idNone。_

你知道我做错了什么吗?

0 投票
2 回答
1684 浏览

django-simple-history - django-simple-history,没有历史记录的保存不起作用

我是 django-simple-history 的忠实粉丝,但是当我在模型的默认 save() 方法中使用“save_without_historical_record”时,我似乎无法正常工作。

我有这样的模型

它有一个自定义的 save() 方法,它用新创建的对象的 id 重命名质粒映射。为了做到这一点,我第一次保存对象以获取它的 id,然后用它来重命名质粒_map。我不想为第一次保存保存历史记录,而只想为第二次保存。我的自定义 save() 方法如下所示

这不起作用,因为每次创建质粒时我仍然会得到“重复”的历史记录。

提前非常感谢。

0 投票
1 回答
512 浏览

django - Django Simple History, need a queryset to sort changes to model by date?

I'm creating a web app that will manage inventory that is placed in boxes. I have installed simple history in Django.

Im trying to write a queryset that returns changes to a boxes contents and orders this data by the date in which this change of content occurred

At the moment I have in my views.py

In my HTML:

This displays the box alongside its contents and also the date it was changed. However, its still not ordering the results by this date. Is there something I can do to change this? Thank you very much in advance.

Current table that is not ordering by date (note project/ box refer to the same thing for the purposes of this question)

0 投票
1 回答
114 浏览

javascript - 替换 HTML 表格中的值?

我正在制作一个 HTML 表格来显示已添加、删除和更改的框(在储藏室中)。标题表示盒子的所有者、发生的变化类型和盒子的新内容。

我使用 Django 作为我的后端。

我可以将“变更类型”中的值翻译成英文单词而不是符号(~、- 和 +)吗?我正在使用 Django simple-history 来记录我的模型的更改并返回这些符号。我希望我的表格能够恭敬地阅读“已更改”、“已删除”和“已添加”来代替“~”、“-”和“+”。

我的桌子

这是 view.py:

的HTML: