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.x Django 4.2 Django 3.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.