django-notifications: how NOTIFICATIONS_SOFT_DELETE=True works?

陌路散爱 提交于 2019-12-11 13:59:07

问题


I want a notification system for my app, so I was looking into a django package called django-notifications. I understood all of it but NOTIFICATION_SOFT_DELETE=True settings.

I mean when I do the following:

from notifications import notify
notify.send(user, recipient=user, verb='you reached level 10')

This will make an entry to the database with deleted=False if I am not wrong. I have the following in my settings.py:

NOTIFICATIONS_SOFT_DELETE=True

which updates to deleted=False to deleted=True. But I don't know when this change happens. There is one API in documentation which marks all notifications as deleted=True:

qs.mark_all_as_deleted() | qs.mark_all_as_deleted(recipient)

Mark all notifications in the queryset (optionally also filtered by recipient) as deleted=True. Must be used with NOTIFICATIONS_SOFT_DELETE=True.

but how to mark some notifications to be deleted??


回答1:


here is the offical documents:

Soft delete

By default, delete/(?P<slug>\d+)/ deletes specified notification record from DB. You can change this behaviour to "mark Notification.deleted field as True" by:

Add to your settings.py: NOTIFICATIONS_SOFT_DELETE=True With this option, QuerySet methods unread and read contain one more filter: deleted=False. Meanwhile, QuerySet methods deleted, active, mark_all_as_deleted, mark_all_as_active are turned on. See more details in QuerySet methods section.

qs.mark_all_as_deleted() | qs.mark_all_as_deleted(recipient)

Mark all notifications in the queryset (optionally also filtered by recipient) as deleted=True. Must be used with NOTIFICATIONS_SOFT_DELETE=True.

so, if you want to mark some notifications to be deleted,you can do either of these

  1. at frontend just call API of delete/(?P<slug>\d+)/
  2. at backend query notifications and call mark_all_as_deleted() or mark_all_as_deleted(recipient)


来源:https://stackoverflow.com/questions/29861473/django-notifications-how-notifications-soft-delete-true-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!