This function mangles a generated form class to remove the Hold down "Control", or "Command"... messages from the help text. This is really a dirty hack awaiting a proper solution to Django ticket 9321.
This function can be useful for forms in the admin interface that use custom widgets. Basic usage:
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
class MyAdmin(admin.ModelAdmin):
form = remove_holddown(MyModelForm, ('field1', 'field2'))
1 2 3 4 5 6 7 8 9 | def remove_holddown(form, fields):
"""This removes the unhelpful "Hold down the...." help texts for the
specified fields for a form."""
remove_message = unicode(_('Hold down "Control", or "Command" on a Mac, to select more than one.'))
for field in fields:
if field in form.base_fields:
if form.base_fields[field].help_text:
form.base_fields[field].help_text = form.base_fields[field].help_text.replace(remove_message, '').strip()
return form
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 8 months ago
Comments
**need in 8 line:
form.base_fields[field].help_text = ugettext_lazy(form.base_fields[field].help_text.replace(remove_message,''))<br /> but anyway i don't can change in django this problem
#
This is not going to work as that is too early in the code to remove the help text. You need to override the method
formfield_for_manytomany()
:#
Please login first before commenting.