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()