我已经对此进行了一段时间的工作,并希望创建facebook-like notification系统。我的项目有以下特性
在搜索了很多之后,我发现有一篇文章说,django-订阅可以为它提供最好的解决方案,但是在阅读了这些文档之后,我走到了死胡同。我在windows上进行开发,当我试图运行测试时,失败了。
而且,文档是非常不清楚的,我不知道事情将如何运作。谁能给我指明正确的方向。
发布于 2021-12-15 12:47:48
你通过信号做得更好。如果有什么事情发生,创建给订阅者发送电子邮件。
@receiver(post_save, sender=BlogPost)
def send_mail_to_subs(sender, instance, created, **kwargs):
if created:
for subs in instance.author.subscribed.all():
send_mail(
f'New Post from {instance.author}',
f'Title: {instance.post_title}',
'youremail',
[subs.email],
)良好的编码:)
https://stackoverflow.com/questions/8602951
复制相似问题