Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Made m2m fields form help_text munging specific to admin widgets.

Refs #9321 and follow-up to e80de93.
  • Loading branch information...
1 parent e61d99d commit 491419b5ffac3752a1c1804a763c017a2ed82e16 @ramiro ramiro committed
Showing with 20 additions and 1 deletion.
  1. +8 −1 django/contrib/admin/
  2. +12 −0 tests/admin_widgets/
9 django/contrib/admin/
@@ -30,6 +30,7 @@
from django.forms.formsets import all_valid, DELETION_FIELD_NAME
from django.forms.models import (modelform_factory, modelformset_factory,
inlineformset_factory, BaseInlineFormSet, modelform_defines_fields)
+from django.forms.widgets import SelectMultiple, CheckboxSelectMultiple
from django.http import Http404, HttpResponseRedirect
from django.http.response import HttpResponseBase
from django.shortcuts import get_object_or_404
@@ -41,6 +42,7 @@
from django.utils.html import escape, escapejs
from django.utils.http import urlencode
from django.utils.text import capfirst, get_text_list
+from django.utils.translation import string_concat
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.utils.safestring import mark_safe
@@ -280,7 +282,12 @@ def formfield_for_manytomany(self, db_field, request=None, **kwargs):
if queryset is not None:
kwargs['queryset'] = queryset
- return db_field.formfield(**kwargs)
+ form_field = db_field.formfield(**kwargs)
+ if isinstance(form_field.widget, SelectMultiple) and not isinstance(form_field.widget, CheckboxSelectMultiple):
+ msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
+ help_text = form_field.help_text
+ form_field.help_text = string_concat(help_text, ' ', msg) if help_text else msg
+ return form_field
def get_view_on_site_url(self, obj=None):
if obj is None or not self.view_on_site:
12 tests/admin_widgets/
@@ -19,6 +19,7 @@
from django.db.models import CharField, DateField
from django.test import TestCase as DjangoTestCase
from django.test import override_settings
+from django.utils import six
from django.utils import translation
from . import models
@@ -168,6 +169,17 @@ def testChoicesWithRadioFields(self):
def testInheritance(self):
self.assertFormfield(models.Album, 'backside_art', widgets.AdminFileWidget)
+ def test_m2m_widgets(self):
+ """m2m fields help text as it applies to admin app (#9321)."""
+ class AdvisorAdmin(admin.ModelAdmin):
+ filter_vertical = ['companies']
+ self.assertFormfield(models.Advisor, 'companies', widgets.FilteredSelectMultiple,
+ filter_vertical=['companies'])
+ ma = AdvisorAdmin(models.Advisor,
+ f = ma.formfield_for_dbfield(models.Advisor._meta.get_field('companies'), request=None)
+ self.assertEqual(six.text_type(f.help_text), 'Hold down "Control", or "Command" on a Mac, to select more than one.')
class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):

0 comments on commit 491419b

Please sign in to comment.
Something went wrong with that request. Please try again.