Opened 14 years ago
Last modified 9 years ago
#14402 closed Bug
help_text is not displayed for ManyToMany raw_id fields — at Version 12
Reported by: | Germano Gabbianelli | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | raw_id_fields |
Cc: | Germano Gabbianelli, chris@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
if db_field.name in self.raw_id_fields: kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel, using=db) kwargs['help_text'] = ''
In contrib.admin.options.BaseModelAdmin.formfield_for_manytomany
the help_text is reset to ""
because otherwise ManyToManyField.__init__
would append 'Hold down "Control", or "Command"...' to it:
msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.') self.help_text = string_concat(self.help_text, ' ', msg)
Change History (13)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.2 → SVN |
follow-up: 3 comment:2 by , 14 years ago
Has patch: | set |
---|
The attached fix involves moving the "Hold down the Control key..." literal as the default help_text
from its historically location in the model M2M field to the respective form field (ModelMultipleChoiceField
). This way, it's available to the default form widget and the admin-specific FilteredSelectMultiple
widget.
In IRC discussions, one idea suggested was to push this even more in the presentation layer by moving it to the widget realm (that would be more correct because it wouldn't force that help text on potential custom widgets whose operation doesn't involve selecting things with mouse clicks and Contrl/Command keypresses). The only problem I see with this is that it would mean we should put and maintain the "Hold down the Control key..." literal in two locations (SelectMultiple
and FilteredSelectMultiple
). Hopefully the tests contained in the patch are of help if this is the chosen path.
comment:3 by , 14 years ago
Replying to ramiro:
The attached fix involves moving the "Hold down the Control key..." literal as the default
help_text
from its historically location in the model M2M field to the respective form field (ModelMultipleChoiceField
). This way, it's available to the default form widget and the admin-specificFilteredSelectMultiple
widget.
It's surely a good thing to move it away from ManyToManyField
, because otherwise it won't be possible to recover the original help_text
set by the user.
However I don't understand what do you mean by saying that it's available to the widgets. ( I can't find neither in admin/widgets.py nor in forms/widgets.py how and where help_text
is used by any widget ).
In IRC discussions, one idea suggested was to push this even more in the presentation layer by moving it to the widget realm (that would be more correct because it wouldn't force that help text on potential custom widgets whose operation doesn't involve selecting things with mouse clicks and Contrl/Command keypresses). The only problem I see with this is that it would mean we should put and maintain the "Hold down the Control key..." literal in two locations (
SelectMultiple
andFilteredSelectMultiple
). Hopefully the tests contained in the patch are of help if this is the chosen path.
Granted that I wouldn't know how to do it, I think this is the only good solution. Maintaining two strings one for each widget that requires it doesn't seem a problem to me.
I am saying this because your patch doesn't seem to fix the problem. Infact you moved the help_text to ModelMultipleChoiceField
but raw_id fields use that formfield too.
This means that the inappropriate help_text, for raw_id fields, will get appended to their help_texts. Actually what you did forces raw_id field to always have at least the "Hold down the Control key..." inappropriate help_text.
Moreover about the template file, using field.field.field.help_text
or field.field.help_text
shouldn't be different because field
is an AdminField
, field.field
is a forms.BoundField
and its help text is set like this:
self.help_text = field.help_text or ''
(I have not tested the differences, though.)
comment:4 by , 14 years ago
Cc: | added |
---|
comment:6 by , 14 years ago
Cc: | added |
---|
comment:7 by , 14 years ago
milestone: | → 1.4 |
---|
I think this is the manifestation of a broader issue in #9321. I recommend solving both those tickets at once.
comment:8 by , 14 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Bug |
Just pointing out that I have just attached a patch to #9321 which would solve both tickets at once thanks to the introduction of a new Widget.alter_help_text
method.
comment:9 by , 13 years ago
UI/UX: | set |
---|
comment:12 by , 12 years ago
Description: | modified (diff) |
---|
Yes, not sure what the right solution is, but it should be possible to set custom help text for an m2m raw id widget.