如何解决通过断开django-notifications-hq
我打算在创建信号后通过断开视图中的信号来断开 django-notifications-hq 包中的通知:
例如:
def view1:
notify.send(sender=user,recipient=other_user,verb=message,target=object)
return redirect('app:page')
def view2:
notify.disconnect(sender=user,reciever=other_user)
return redirect('app:page2')
在此示例中,user和other_user是相同的用户
这将断开user
和other_user
之间的所有信号,我打算做的只是断开那些用户之间为该特定对象创建的信号。
我已经研究过源代码,但找不到如何做这样的事情。
GitHub 链接供您参考:https://github.com/django-notifications/django-notifications
这也是该软件包中的Signals file:
''' Django notifications signal file '''
# -*- coding: utf-8 -*-
from django.dispatch import Signal
notify = Signal(providing_args=[ # pylint: disable=invalid-name
'recipient','actor','verb','action_object','target','description','timestamp','level'
])
编辑
这是我要实现的目标的更清晰示例:
在我的app/views.py
我有:
def post_like(request,id):
post = get_objects_or_404(Post,id=id)
if request.user in post.likes:
post.likes.remove(request.user)
# remove notification sent to post.author here
elif request.user not in post.likes:
post.likes.add(request.user)
notify.send(sender=request.user,recipient=post.author,verb="Liked your post",target = post)
"""
Continue other functions here
"""
该视图该如何连接和断开信号?我在文档中找不到示例。
编辑
我正在尝试根据通知模型字段获取特定的通知:
request.user.notifications.get(actor_content_type__model='Profile',actor_object_id=request.user.id,target_content_type__model='home.Post',target_object_id=post.id,verb=message)
我遇到一个错误:
raise self.model.DoesNotExist(
main.models.Notification.DoesNotExist: Notification matching query does not exist.
查看更多内容后,我注意到:
AttributeError: 'Notification' object has no attribute 'actor_content_type__model'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。