1

I need to send a mail only when the model is saved from django admin, I was trying with sender.user.is_superuser but i couldn't find the specific method

El.
  • 1,217
  • 1
  • 13
  • 23
acoto
  • 53
  • 3

2 Answers2

0

Not Possible:

Accessing the user's request in a post_save signal

"Can't be done. The current user is only available via the request, which is not available when using purely model functionality. Access the user in the view somehow."

"Django's model signals are intended to notify other system components about events associated with instances and their respected data"

Possible Solution:

https://stackoverflow.com/a/35145746/3466907

Community
  • 1
  • 1
Rio Weber
  • 2,757
  • 1
  • 20
  • 28
0

You can't do this with a signal, but you can do it with your ModelAdmin's save_model() method.

For example:

from django.contrib import admin
from django.core.mail import send_mail

class MyModelAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        super().save_model(request, obj, form, change)
        send_mail(...)
Tom Carrick
  • 6,349
  • 13
  • 54
  • 78