Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除django通知总部的通知_Python_Django_Django Models_Django Views - Fatal编程技术网

Python 删除django通知总部的通知

Python 删除django通知总部的通知,python,django,django-models,django-views,Python,Django,Django Models,Django Views,我正在为我的通知系统使用包django notifications hq,但是,我无法使用我的视图删除通知 现在,在包中的通知模型中,我们有: recipient = models.ForeignKey( settings.AUTH_USER_MODEL, blank=False, related_name='notifications', on_delete=models.CASCADE ) actor_content_type = models.Forei

我正在为我的通知系统使用包
django notifications hq
,但是,我无法使用我的视图删除通知

现在,在包中的通知模型中,我们有:

recipient = models.ForeignKey(
    settings.AUTH_USER_MODEL,
    blank=False,
    related_name='notifications',
    on_delete=models.CASCADE
)


actor_content_type = models.ForeignKey(ContentType, related_name='notify_actor', on_delete=models.CASCADE)
actor_object_id = models.CharField(max_length=255)
actor = GenericForeignKey('actor_content_type', 'actor_object_id')



target_content_type = models.ForeignKey(
    ContentType,
    related_name='notify_target',
    blank=True,
    null=True,
    on_delete=models.CASCADE
)
target_object_id = models.CharField(max_length=255, blank=True, null=True)
target = GenericForeignKey('target_content_type', 'target_object_id')
我正在尝试使用
request.user.notifications

但是,每次我出现错误时:

<class 'notifications.models.Notification.DoesNotExist'>
在上面的示例中,request.user是post.author

如何删除视图中的通知

from django.contrib.admin.options import get_content_type_for_model   
request.user.notifications.get(actor_content_type=get_content_type_for_model(user),actor_object_id=str(user.id),\
                             recipient=post.author, verb=message, target_content_type=get_content_type_for_model(post), target_object_id=str(post.id)).delete()