django-notifications:NOTIFICATIONS_SOFT_DELETE = True如何工作? [英] django-notifications: how NOTIFICATIONS_SOFT_DELETE=True works?

查看:179
本文介绍了django-notifications:NOTIFICATIONS_SOFT_DELETE = True如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个用于我的应用程序的通知系统,所以我正在研究一个名为django-notifications的django软件包.我了解所有内容,但NOTIFICATION_SOFT_DELETE =正确的设置.

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

如果我没有记错的话,这将使用deleted=False进入数据库.我的settings.py中有以下内容:

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

,它将更新为deleted=Falsedeleted=True.但是我不知道什么时候发生这种变化.文档中有一个API将所有通知标记为deleted=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(收件人)

标记查询集中的所有通知(也可以通过过滤 收件人)为已删除=真.必须与 NOTIFICATIONS_SOFT_DELETE =是.

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

但是如何将某些通知标记为deleted ??

but how to mark some notifications to be deleted??

推荐答案

以下是官方文档:

软删除

默认情况下,delete/(?P<slug>\d+)/从数据库中删除指定的通知记录.您可以通过以下方式将此行为更改为将Notification.deleted字段标记为True":

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:

添加到您的设置中.py:NOTIFICATIONS_SOFT_DELETE=True 使用此选项,未读和已读的QuerySet方法包含另一个过滤器:Deleted = False.同时,已打开已删除,活动,mark_all_as_deleted,mark_all_as_active的QuerySet方法.在QuerySet方法部分中查看更多详细信息.

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)

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

将查询集中的所有通知(可选地也由收件人过滤)标记为deleted=True.必须与NOTIFICATIONS_SOFT_DELETE=True一起使用.

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. 在前端只需调用delete/(?P<slug>\d+)/
  2. 的API
  3. 在后端查询通知中,并调用mark_all_as_deleted()mark_all_as_deleted(recipient)
  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)

这篇关于django-notifications:NOTIFICATIONS_SOFT_DELETE = True如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆