问题描述
我如何在Django信号中使用多个实例和发送者(不同的模型)。
receiver(post_save,sender=Comment)
@receiver(post_save,sender=Post)
def create_comment_notification(*args,**kwargs):
#comments notifier
comment = kwargs['instance']
post = kwargs['instance']
if kwargs['created']:
if comment.author != comment.post_connected:
Notification.objects.create(
assigned_to = post.author,group='NC',body=f"{comment.author} commented: {comment.content} on your post.",pk_relation=comment.id
)
else:
if comment.author != comment.post_connected:
Notification.objects.create(
assigned_to = post.author,body=f"{comment.author} commented: {comment.content}.",pk_relation=comment.id
)
我注意到它可以工作,但是无法识别POST模型,它仅使用COMMENT。我如何使用这两种模型作为发件人。并让代码分别识别它们。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)