Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions django/contrib/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.contrib.admin.options import (
HORIZONTAL,
VERTICAL,
ActionLocation,
ModelAdmin,
ShowFacets,
StackedInline,
Expand All @@ -24,6 +25,7 @@

__all__ = [
"action",
"ActionLocation",
"display",
"register",
"ModelAdmin",
Expand Down
10 changes: 5 additions & 5 deletions django/contrib/admin/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,10 @@ def _check_actions(self, obj):

# Actions with an allowed_permission attribute require the ModelAdmin
# to implement a has_<perm>_permission() method for each permission.
for func, name, _ in actions:
if not hasattr(func, "allowed_permissions"):
for action in actions:
if not hasattr(action.func, "allowed_permissions"):
continue
for permission in func.allowed_permissions:
for permission in action.func.allowed_permissions:
method_name = "has_%s_permission" % permission
if not hasattr(obj, method_name):
errors.append(
Expand All @@ -1260,14 +1260,14 @@ def _check_actions(self, obj):
% (
obj.__class__.__name__,
method_name,
func.__name__,
action.func.__name__,
),
obj=obj.__class__,
id="admin.E129",
)
)
# Names need to be unique.
names = collections.Counter(name for _, name, _ in actions)
names = collections.Counter(action.name for action in actions)
for name, count in names.items():
if count > 1:
errors.append(
Expand Down
19 changes: 18 additions & 1 deletion django/contrib/admin/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
def action(function=None, *, permissions=None, description=None):
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::

Expand All @@ -23,6 +33,13 @@ def decorator(func):
func.allowed_permissions = permissions
if description is not None:
func.short_description = description
if description_plural is not None:
func.plural_description = description_plural
elif description is not None:
func.plural_description = description
func.locations = (
[location] if isinstance(location, ActionLocation) else location
)
return func

if function is None:
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/admin/locale/en/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: Django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-25 15:04-0500\n"
"PO-Revision-Date: 2010-05-13 15:35+0200\n"
"PO-Revision-Date: 2026-05-11 15:27-0400\n"
"Last-Translator: Django team\n"
"Language-Team: English <en@li.org>\n"
"Language: en\n"
Expand Down Expand Up @@ -103,7 +103,7 @@ msgstr ""
#: contrib/admin/static/admin/js/actions.js:175
msgid ""
"You have selected an action, and you haven’t made any changes on individual "
"fields. You’re probably looking for the Go button rather than the Save "
"fields. You’re probably looking for the Run button rather than the Save "
"button."
msgstr ""

Expand Down
Loading
Loading