通过断开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是相同的用户

这将断开userother_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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...