django-admin-extra-buttons

raw JSON →
2.2 verified Fri May 01 auth: no python

Django mixin to easily add custom buttons to any ModelAdmin, change form, or changelist. Current version is 2.2, requires Python >=3.12 and Django >=4.2 (implicitly). The library is actively maintained with regular releases.

pip install django-admin-extra-buttons
error AttributeError: 'MyModelAdmin' object has no attribute 'button'
cause Trying to use button as a method without decorating or mixing in ExtraButtonsMixin.
fix
Ensure your ModelAdmin inherits from ExtraButtonsMixin first. Example: class MyModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
error django.core.exceptions.ImproperlyConfigured: The 'extra_buttons' attribute 'button' does not exist on model admin 'MyModelAdmin'
cause Missing @button decorator or misspelled method name (extra_buttons expects decorated methods).
fix
Add @button decorator above the method and ensure the method is inside the admin class with ExtraButtonsMixin.
error TypeError: button() got an unexpected keyword argument 'permission'
cause Using an older version (<1.6) where permission argument is not supported.
fix
Upgrade to latest version: pip install --upgrade django-admin-extra-buttons
breaking Version 2.0 dropped support for Django <3.2 and Python <3.8. If upgrading from 1.x, review changes in get_urls() method and ensure your custom views are compatible.
fix Upgrade to Django >=3.2 and Python >=3.8. Review custom get_urls() overrides for compatibility with new URL patterns.
gotcha The button decorator's `permission` argument is a string, not a callable. Using a callable will cause a TypeError or be ignored.
fix Use 'app_label.permission_codename' string format. For dynamic checks, use Django's perms in the request.
gotcha When using @choice or @button on methods that also have @admin.display, the button will not render properly. Do not mix these decorators.
fix Define button methods separately from list display methods.
deprecated The `buttons` property (list of dicts) is deprecated in favor of the decorator-based approach as of v1.6. It will be removed in a future release.
fix Refactor to use decorators (@button, @choice, @link, @view) instead of defining buttons dict.

Add a custom button to a ModelAdmin using ExtraButtonsMixin and the button decorator.

from django.contrib import admin
from admin_extra_buttons.mixins import ExtraButtonsMixin
from admin_extra_buttons.decorators import button
from django.http import HttpResponse

class MyModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
    @button(label='Say Hello', permission='some_app.can_view')
    def say_hello(self, request):
        return HttpResponse('Hello!')

admin.site.register(MyModel, MyModelAdmin)