summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/templates/admin/change_form.html6
-rw-r--r--django/forms/forms.py11
2 files changed, 14 insertions, 3 deletions
diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
index 7c96628963..08347abe78 100644
--- a/django/contrib/admin/templates/admin/change_form.html
+++ b/django/contrib/admin/templates/admin/change_form.html
@@ -16,8 +16,8 @@
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
- <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
- {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
+ <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
+ {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endif %}{% endblock %}
@@ -56,7 +56,7 @@
{% submit_row %}
{% if adminform and add %}
- <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
+ <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
{% endif %}
{# JavaScript for prepopulated fields #}
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 46e97ef5b9..b520d7e32e 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -518,3 +518,14 @@ class BoundField(StrAndUnicode):
return self.html_name
return ''
auto_id = property(_auto_id)
+
+ def _id_for_label(self):
+ """
+ Wrapper around the field widget's `id_for_label` class method.
+ Useful, for example, for focusing on this field regardless of whether
+ it has a single widget or a MutiWidget.
+ """
+ widget = self.field.widget
+ id_ = widget.attrs.get('id') or self.auto_id
+ return widget.id_for_label(id_)
+ id_for_label = property(_id_for_label)