问题
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 withNOTIFICATIONS_SOFT_DELETE=True
.
so, if you want to mark some notifications to be deleted,you can do either of these
- at frontend just call API of
delete/(?P<slug>\d+)/
- at backend query notifications and call
mark_all_as_deleted()
ormark_all_as_deleted(recipient)
来源:https://stackoverflow.com/questions/29861473/django-notifications-how-notifications-soft-delete-true-works