Question

I have a boolean field in my model indicating, that email with some info to the user was sent. When I update it in admin I use save() method from the model, and there actually the email is being sent. And this works.

BUT:

When I try to use my actions defined like this:

def send_this_email(modeladmin, request, queryset):
    queryset.update(mail_sent=True)
send_this_email.short_description = "Send email with access data"

and in admin class:

actions = [send_this_email]

The method save() seems not being executed and email is not sent. How can I force my send_this_email to execute save?

If it matters I am using grappeli for my django admin.

Was it helpful?

Solution

Django's documentation specifies that calling update() on a queryset will not call save or invoke any pre-/post-save hooks. I suggest you call the function explicitly when the email needs to get sent.

Alternatively, you can call save() in the admin function, but then you lose the benefits of the update() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top