相关疑难解决方法(0)

Django:确定在使用post_delete信号时哪个用户正在删除

我希望管理员在删除某些对象时收到通知,但我也想确定哪个用户正在执行删除.

可能吗?

这是代码:

# models.py
# signal to notify admins when nodes are deleted
from django.db.models.signals import post_delete
from settings import DEBUG

def notify_on_delete(sender, instance, using, **kwargs):
    ''' Notify admins when nodes are deleted. Only for production use '''
    if DEBUG:
        #return False
        pass
    # prepare context
    context = {
        'node': instance,
        'site': SITE
    }
    # notify admins that want to receive notifications
    notify_admins(instance, 'email_notifications/node-deleted-admin_subject.txt', 'email_notifications/node-deleted-admin_body.txt', context, skip=False)

post_delete.connect(notify_on_delete, sender=Node)
Run Code Online (Sandbox Code Playgroud)

python django django-signals django-models django-sessions

6
推荐指数
1
解决办法
1553
查看次数