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
Asked
Active
Viewed 1,335 times
1
2 Answers
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:
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