﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32099	Admin action decorators	Michal Dabski	nobody	"Currently django admin actions can be customized by adding arbitrary properties to the action method or function (allowed_permissions , short_description). This method is not very discoverable, and rather un-puthonic.

Proposed solution:
Django should provide a built-in decorator that wrap action callable and adds any properties passed to the decorator. Because decorator can define available properties in it's signature, this method will be less error-prone and will make it easier to discover properties available to admin actions.
As an added bonus, a decorator could maybe even add the action to the `actions` list without the user having to do it explicitly.

Example:

{{{
@admin.register(models.Document)
class DocumentAdmin(ModelAdmin):
    actions = 'publish',

    def publish(self, request, qs):
        qs.update(publish=True)
    publish.short_description = _('publish document')
    publish.allowed_permissions =[ 'change']
}}}

could become:

{{{
@admin.register(models.Document)
class DocumentAdmin(ModelAdmin):
    actions = 'publish',

    @action(short_description=_('publish document'), allowed_permissions=['change'])
    def publish(self, request, qs):
        qs.update(publish=True)
}}}

This functionality is implemented by a third-party library, but it has not been updated in 9 years:
https://github.com/kmike/django-admin-decorators"	Cleanup/optimization	closed	contrib.admin	dev	Normal	duplicate	admin,actions,decorator		Unreviewed	1	0	1	0	1	0
