Reputation: 77
I have a Django application where a user enters an e-mail address in a form, amongst the other fields that they have to fill in. In my Django admin, it displays the typed results from all these fields. What I'd like to add is a button beside the e-mail field in the admin view to send an e-mail to the entered address. How would I go about this? Would I need to edit the admin page template or model, perhaps?
Upvotes: 0
Views: 407
Reputation: 541
You could add an boolean field "email_on_save" and a text field for the "message". When the record gets saved in the admin it calls the Model.save() method.
You extend the model.save() this way:
def save(self, *args, **kwargs):
if self.email_on_save:
send_email(self.email, self.message)
self.email_on_save = False
self.message = ""
# Call super save method
return super(MyModel, self).save(*args, **kwargs)
Upvotes: 1