Login

remove the annoying "Hold down control..." messages

Author:
arthur
Posted:
March 23, 2011
Language:
Python
Version:
1.2
Tags:
admin forms hack widget
Score:
0 (after 0 ratings)

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

  1. AjaxForm Base Classes by btaylordesign 4 years ago
  2. DropDownMultiple widget by marinho 6 years, 10 months ago
  3. Admin Image Widget by baumer1122 6 years, 7 months ago
  4. ImageField for admin with thumbnail by semente 5 years, 9 months ago
  5. Hidden Date Display Widget for Admin by andrew.schoen 5 years, 8 months ago

Comments

malinich (on March 27, 2013):

**need in 8 line:

form.base_fields[field].help_text = ugettext_lazy(form.base_fields[field].help_text.replace(remove_message,''))
but anyway i don't can change in django this problem

#

Please login first before commenting.