Re: [Django] #33805: SelectMultiple in ModelAdminForm display help text when allow_multiple_selected is False. (was: SelectMultiple in ModelAdminForm help_text render)

5 views
Skip to first unread message

Django

unread,
Jun 24, 2022, 4:38:18 AM6/24/22
to django-...@googlegroups.com
#33805: SelectMultiple in ModelAdminForm display help text when
allow_multiple_selected is False.
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
AdminForm |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

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:
{{{#!diff
diff --git a/django/contrib/admin/options.py
b/django/contrib/admin/options.py
index a25814b5fb..f959a8dc48 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -314,8 +314,12 @@ class
BaseModelAdmin(metaclass=forms.MediaDefiningClass):
kwargs["queryset"] = queryset

form_field = db_field.formfield(**kwargs)
- if isinstance(form_field.widget, SelectMultiple) and not
isinstance(
- form_field.widget, (CheckboxSelectMultiple,
AutocompleteSelectMultiple)
+ if (
+ isinstance(form_field.widget, SelectMultiple)
+ and form_field.widget.allow_multiple_selected
+ and not isinstance(
+ form_field.widget, (CheckboxSelectMultiple,
AutocompleteSelectMultiple)
+ )
):
msg = _(
"Hold down “Control”, or “Command” on a Mac, to select
more than one."

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33805#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages