Django admin actions are a great new feature available in the development version which allows you to easily extend the admin interface for doing bulk actions.
The basic workflow for the django admin in the past has always been “Select an object, then change it.” — Now, we have the ability to do bulk edits, deletes or whatever custom utility floats our boat. The official documentation explains admin actions in extreme detail very well, but I will run through a quick example!
Within admin.py, we define our admin class and custom action
class ProfileAdmin(admin.ModelAdmin):
actions = ['send_verify_email']
def send_verify_email(self, request, queryset):
"""
Loop through all objects the user has selected and call our custom function.
"""
for obj in queryset:
Profile.objects.send_verify_email(obj.user)
self.message_user(request, "%s users were successfully emailed for re-verification" % len(queryset))
send_verify_email.short_description = 'Verify Email Addresses'
To summarize the code, here’s what’s important:
And that’s it! With this and some code within my manager function, I can now send out bulk emails to my users with a few clicks. Of course, this is just a simple example and I totally recommend reading the admin actions documentation