Tôi muốn quản trị viên được thông báo khi một số đối tượng nhất định bị xóa nhưng tôi cũng muốn xác định người dùng nào đang thực hiện xóa.Django: xác định người dùng nào đang xóa khi sử dụng tín hiệu post_delete
Có thể không?
Đây là mã:
# 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)
Nó sẽ không thể tốt hơn nếu các tín hiệu đã bị sa thải khỏi bởi mô hình thay cho lượt xem? Do đó giao diện quản trị và mã của bên thứ ba vẫn hoạt động? –
@Jack M. Tôi đoán điều đó sẽ tốt hơn, nhưng sau đó làm thế nào để bạn tìm ra 'Người dùng' nào đang thực hiện xóa mà không có' yêu cầu'? –