About Form Wizards in Administration

You can create a custom form to send emails, tweet, or do some external action in administration by creating an unmanaged model with a custom save() method:

class NewEmailMessage(models.Model):
    sender = models.EmailField(_("Sender"))
    recipient = models.EmailField(_("Recipient"))
    subject = models.CharField(_("Subject"), max_length=255)
    body = models.TextField(_("Body"), blank=True)

    class Meta:
        managed = False

    def save(self, *args, **kwargs):
        send_mail(
            subject=self.subject, message=self.body,
            from_email=self.sender, recipient_list=[self.recipient],
        )

Then in the administration of this model, disable the actions to view, edit, and delete:

@admin.register(NewEmailMessage)
class NewEmailMessageAdmin(admin.ModelAdmin):
    fields = ("sender", "recipient", "subject", "body")

    def has_add_permission(self, request):
        return True

    def has_change_permission(self, request, obj=None):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    def has_view_permission(self, request, obj=None):
        return False

Tips and Tricks Programming Architecture Development Django 5.2 Django 4.2 Django 3.2

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.