I want administrators to be notified when some objects are deleted, but I also want to determine which user is performing the deletion.
Is it possible?
This is the code:
# 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)
python django django-models django-signals django-sessions
nemesisdesign
source share