Django - 扩展 LogEntry
我要求每当添加/更改/删除模型时,它都应该发送邮件通知。内容将更像 django_admin_log 条目。我只需要在我的模型中扩展此功能即可发送邮件。有什么建议吗?
I have the requirement that whenever there is a model get's added/changed/deleted, it should send a mail notification. The content will be more like the django_admin_log entries. I just need to extend this functionality in my model to send the mail. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Django_log_admin 将仅跟踪管理界面中所做的更改。如果模型在其他地方发生更改,则不会更新日志。但是,如果您只接受管理更改,那么您可以使用 django_log_admin 和 post_save 信号的组合来实现这一目的。将其放入您的 management.py 中:
自我提示:哇,django 确实包含所有电池:D
Django_log_admin will only track changes made in the admin interface. If the model is changed anywhere else, it will not update the log. However, if you are OK with just admin changes, then you can use a combination of django_log_admin and the post_save signal to do the trick. Put this in your management.py:
note to self: wow, django really includes all the batteries :D
您应该查看 Django 的 信号。对于您的情况,首先,您将把处理程序连接到
post_save
和post_delete
信号。查看内置信号文档,了解您可能想要利用的其他信号。无需侵入admin
。You should look at Django's signals. In your case, you'll connect your handlers to the
post_save
andpost_delete
signals, for starters. Look through the built-in signal documentation for others you may want to tap. No need to hack intoadmin
.