如何从django-simple-history中指定一个生成的模型类作为信号的发送者?

问题描述 投票:0回答:1

我想监听 pre_create_historical_record 由simple-history包提供的信号,但只能来自特定的sender。问题是历史模型是由simple-history生成的,我不知道如何导入类 "core.HistoricalUser "作为一个类型来设置为sender。

python django django-signals django-simple-history
1个回答
1
投票

你可以通过历史管理器进入模型类,就像文档中描述的那样。此处.

在你的特定情况下,类似于--假设你的历史记录管理器被称为 history 而您要跟踪历史的型号是 User:

pre_create_historical_record.connect(
    signal_receiver_function, 
    sender=User.history.model
)
© www.soinside.com 2019 - 2024. All rights reserved.