Opened 3 years ago
Closed 3 years ago
#33805 closed Cleanup/optimization (fixed)
SelectMultiple in ModelAdminForm display help text when allow_multiple_selected is False.
| Reported by: | Maxim Danilov | Owned by: | Ankur Roy |
|---|---|---|---|
| Component: | contrib.admin | Version: | 4.1 |
| Severity: | Normal | Keywords: | modeladmin, AdminForm |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
In AdminForm Help text on render for SelectMultiple widget don't check, if widget.allow_multiple_selected = False.
Widget himself on render checks it
# django.forms.widgets rows 684-685 if self.allow_multiple_selected: context['widget']['attrs']['multiple'] = True
But help_text for widget, whose is rendered behind widget - don't checks it. There we check only "isinstance"
# django.contrib.admin.options.py rows 280-281
if (isinstance(form_field.widget, SelectMultiple) ann not isinstance(form_field.widget, (CheckboxSelectMultiple, AutocompleteSelectMultiple))):
... # do some stuff with help text
as a result I get "msg", which should not be.
Attachments (1)
Change History (7)
by , 3 years ago
| Attachment: | Unbenannt.png added |
|---|
comment:1 by , 3 years ago
| Summary: | SelectMultiple in ModelAdminForm help_text render → SelectMultiple in ModelAdminForm display help text when allow_multiple_selected is False. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
Thanks for the report. As far as I understand correctly, you have a subclass of SelectMultiple with allow_multiple_selected set to False, that's quite niche. However, I agree that we should check allow_multiple_selected in both places:
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index a25814b5fb..f959a8dc48 100644
a b class BaseModelAdmin(metaclass=forms.MediaDefiningClass): 314 314 kwargs["queryset"] = queryset 315 315 316 316 form_field = db_field.formfield(**kwargs) 317 if isinstance(form_field.widget, SelectMultiple) and not isinstance( 318 form_field.widget, (CheckboxSelectMultiple, AutocompleteSelectMultiple) 317 if ( 318 isinstance(form_field.widget, SelectMultiple) 319 and form_field.widget.allow_multiple_selected 320 and not isinstance( 321 form_field.widget, (CheckboxSelectMultiple, AutocompleteSelectMultiple) 322 ) 319 323 ): 320 324 msg = _( 321 325 "Hold down “Control”, or “Command” on a Mac, to select more than one."
comment:2 by , 3 years ago
As far as I understand correctly, you have a subclass of SelectMultiple with allow_multiple_selected set to False.
Exactly.
comment:3 by , 3 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 3 years ago
| Needs tests: | unset |
|---|---|
| Patch needs improvement: | unset |
| Triage Stage: | Accepted → Ready for checkin |
rendered m2m field with allow_multiple_selected=False