Skip to content

Commit 2c73e16

Browse files
committed
Skip the actions dropdown when there's no actions to select
1 parent ecfab20 commit 2c73e16

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

changeform_actions/admin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, Tuple
22

33
from django.template.context import ContextDict
44
from django.template.loader import render_to_string
@@ -71,12 +71,18 @@ def get_changeform_actions_dropdown(self, request, context) -> str:
7171
if not object_id:
7272
return ""
7373

74-
action_form = ActionForm(auto_id=None)
75-
action_form.fields["action"].choices = [
74+
action_choices: Tuple[str, str] = [
7675
(name, label)
7776
for (name, label) in self.get_action_choices(request)
7877
if self.skip_default_delete_action and name != DEFAULT_DELETE_ACTION_NAME
7978
]
79+
if len(action_choices) == 1:
80+
# Only the default '----' option, so no actual actions
81+
# available. No need to render the form.
82+
return ""
83+
84+
action_form = ActionForm(auto_id=None)
85+
action_form.fields["action"].choices = action_choices
8086

8187
return render_to_string(
8288
"admin/actions_for_changeform.html",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "django-admin-changeform-actions"
33
authors = [
44
{ name="Christoph Buelter", email="buelter.christoph@gmail.com" },
55
]
6-
version = "0.5.3"
6+
version = "0.5.4"
77
license = "MIT"
88
description = "Reuse model admin changelist actions on changeform pages"
99
readme = "README.md"

0 commit comments

Comments
 (0)