Skip to main content

Django mixin to easily add buttons to any ModelAdmin

Project description


Pypi coverage Test Docs

my image

This is a full rewriting of the original django-admin-extra-url. It provides decorators to easily add custom buttons to Django Admin pages and/or add views to any ModelAdmin

It allows easy creation of wizards, actions and/or links to external resources as well as api only views.

Three decorators are available:

  • button() to mark a method as extra view and show related button
  • link() This is used for "external" link, where you don't need to invoke local views.
  • view() View only decorator, this adds a new url but do not render any button.
  • choice() Menu like button, can be used to group multiple @views().


pip install django-admin-extra-buttons

After installation add it to INSTALLED_APPS


How to use it

from admin_extra_buttons.api import ExtraButtonsMixin, button, confirm_action, link, view
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
from django.http import HttpResponse, JsonResponse
from django.contrib import admin
from django.views.decorators.clickjacking import xframe_options_sameorigin
from django.views.decorators.csrf import csrf_exempt

class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):

            html_attrs={'style': 'background-color:#88FF88;color:black'})
    def refresh(self, request):
        self.message_user(request, 'refresh called')
        # Optional: returns HttpResponse
        return HttpResponseRedirectToReferrer(request)
    @button(html_attrs={'style': 'background-color:#DC6C6C;color:black'})
    def confirm(self, request):
        def _action(request):

        return confirm_action(self, request, _action, "Confirm action",
                          "Successfully executed", )

          html_attrs={'target': '_new', 'style': 'background-color:var(--button-bg)'})
    def search_on_google(self, button):
        original = button.context['original']
        button.label = f"Search '{}' on Google"
        button.href = f"{}"

    def select2_autocomplete(self, request):
        return JsonResponse({})

    def api4(self, request):
        return HttpResponse("Basic Authentication allowed")

    @view(decorators=[csrf_exempt, xframe_options_sameorigin])
    def preview(self, request):
        if request.method == "POST":
            return HttpResponse("POST")
        return HttpResponse("GET")

Project Links

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-admin-extra-buttons-1.5.7.tar.gz (187.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page