Skip to main content

More buttons in admin

Add more buttons with custom behavior to your admin's submit line.

Using

  1. Add admin_buttons to INSTALLED_APPS:
INSTALLED_APPS = [
    ...,
    "admin_buttons",
]
  1. Mix our class in your ModelAdmin, and define a admin_buttons_config attribute:
from admin_buttons.admin import AdminButtonsMixin
from django.contrib import admin
from django.db import models
from django.shortcuts import redirect


class SpecialModelAdmin[M: models.Model](AdminButtonsMixin, admin.ModelAdmin[M]):
    """
    ModelAdmin for models that do something special. Their special thing
    will be done upon the click of a button
    """

    admin_buttons_config = [
        {
            # the button html name
            "name": "_dosomethingspecial",

            # the method to be called when clicking the button
            "method": "do_something_special",

            # The button label
            "label": _("Do something very special"),

            # Optionally, define a condition. If it does not pass, the
            # button will not be displayed
            "condition": lambda request, context: (
                request.user.has_perm("someperm")
                and not re.search(r"add/?$", request.path)
            ),

            # Optionally, include extra html after the button
            "extra_html": mark_safe_lazy(
                '<input type="number" step=1 min=1 max=99 value=1 '
                'name="n_times" aria-label="'
                f'{_("Number of times do to something special")}">'
            ),

            # Optionally, use a separator before this button:
            use_separator: True,
        },
    ]

    # The chosen method works as a view. Therefore, it should return a response
    # To simply return to the change view, redirect to HTTP_REFERER, as below:
    def do_something_special(self, request: HttpRequest, obj: M | None):
        obj.something_special()
        return redirect(request.META["HTTP_REFERER"])

Development

All contributions are welcome! To setup development:

  1. pip install -r dev.requirements.txt
  2. pre-commit install

Metadata

Release files for django-admin-more-buttons 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-admin-more-buttons 0.0.1
File Size Uploaded Provenance Actions
django_admin_more_buttons-0.0.1.tar.gz 4.5 kB Without provenance Details for django_admin_more_buttons-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-more-buttons 0.0.1
File Interpreter ABI Platform Actions
django_admin_more_buttons-0.0.1-py3-none-any.whl Python 3 none any Details for django_admin_more_buttons-0.0.1-py3-none-any.whl

Total release size: 10.8 kB

Release files / django_admin_more_buttons-0.0.1.tar.gz

Download URL django_admin_more_buttons-0.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f3a9692ebe586c0362bf0e9dd5759403638ceb754f4927af841047ed3a148a9e
BLAKE2b-256 checksum
How to use checksums
1bcc3822defe6b895c69e56a2dea68d5db73ac38d60bf1ba6e9da00442d15f63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / django_admin_more_buttons-0.0.1-py3-none-any.whl

Download URL django_admin_more_buttons-0.0.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96d9f35e3b8cd6c4cbcb13f65cb023cba016e7356e40152c9fb0f58c67896c38
BLAKE2b-256 checksum
How to use checksums
55900248bf0d39162b28d3e535ac4d0bad1c62a07066543da98addd01d07994c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for django-admin-more-buttons 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page