Django-notifications: How Notifications_soft_delete=true Works?
Solution 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)
Solution 2:
This is all you need.
After installing django-notifications-hq and added 'notifications' as an app to your installed app in settings.py and added url('^inbox/notifications/', include(notifications.urls, namespace='notifications')) to your url patterns.
MAKE sure you then install django-notifications-rest and then install 'notifications_rest' as an app next to the one you added as above. Then also add url('^notifications/', include('notifications_rest.urls')) if you are using django v3.0 and below or if you are using v3.1 and above add path('^notifications/', include('notifications_rest.urls')) under urlpatterns in your url file.
Then python manage.py makemigrations. This will create a rest endpoint which you can access on http://localhost:8000/notifications. It is from this end point through your frontend like react you can send an api request to get all unread requests and then mark all requests as read after an onclick event by sending another request through the api.
http://localhost:8000/notifications/all/ will return all requests http://localhost:8000/notifications/unread/ http://localhost:8000/notifications/delete/22 will delete request with id 22 http://localhost:8000/notifications/mark-all-as-read/ will mark all requests as read among all other endpoints you can access.
But i believe in this case, use http://localhost:8000/notifications/unread/ to get all unread requests on page load and then onclick, use http://localhost:8000/notifications/mark-all-as-read/ or http://localhost:8000/notifications/delete/22 to remove or reduce notifications respectively.
Post a Comment for "Django-notifications: How Notifications_soft_delete=true Works?"