Django Admin Decorators (admin/decorators.py)

django · django/contrib/admin/decorators.py · python · BSD-3-Clause
ui, auth, fw:django, tag:decorators, tag:actions

Attaches permissions, labels, and display options to Django admin callables, and registers ModelAdmin classes. Reuse when defining admin actions or customizing changelist columns.

# Source: https://github.com/django/django | License: BSD-3-Clause | Copyright Django Software Foundation and individual contributors
# Provided via justclaw.it.com; keep this notice with the code.
from django.contrib.admin.options import ActionLocation


def action(
    function=None,
    *,
    permissions=None,
    description=None,
    description_plural=None,
    location=ActionLocation.CHANGE_LIST,
):
    """
    Conveniently add attributes to an action function::

        @admin.action(
            permissions=['publish'],
            description='Mark selected stories as published',
        )
        def make_published(self, request, queryset):
            queryset.update(status='p')

    This is equivalent to setting some attributes (with the original, longer
    names) on the fun

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key