在 Django 管理中,我怎样才能知道布尔值第一次被设置为 true
我有一个模型,其中包含一个表示该项目是否批准的布尔字段。 我想在选中该框后发送电子邮件。
我了解如何覆盖保存方法并发送电子邮件(如果是),但这将在每次保存时发送电子邮件。
由于我只想发送一次电子邮件,有没有办法仅在第一次检查布尔值是否为真?
谢谢
I have a model that contains a boolean field representing the item's approval or not.
I'd like to send an email when the box is checked.
I understand how to override the save method and send the email if it's true but this will send an email every time it's saved.
As I only want to send the email once, is there a way to check a boolean is true only for the first time?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我所做的是在保存之前获取数据库中的元素,并将其与之后的内容进行比较。
因此,只有当对象从未批准变为已批准时才会发送电子邮件。
What I do is that I get the element as it's in the database before saving and I compare it to what I have after.
So the email will be send only when the object goes from not approved to approved.