Search code examples
pythondjangodjango-signals

Know if signal is triggered from django admin


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


Solution

  • 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(...)