From 1c0c879be3a21affec3d5eb2d6b6e4f0a0803aec Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 31 Aug 2013 21:04:53 +0200 Subject: [PATCH] Fixed #17074 -- Improved first field detection in admin add form Thanks Kidwind for the report and Julien Phalip for the initial patch. --- django/contrib/admin/helpers.py | 14 -------------- .../contrib/admin/templates/admin/change_form.html | 10 ++++++++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index af1df5e668..a91988bc47 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -46,20 +46,6 @@ class AdminForm(object): **options ) - def first_field(self): - try: - fieldset_name, fieldset_options = self.fieldsets[0] - field_name = fieldset_options['fields'][0] - if not isinstance(field_name, six.string_types): - field_name = field_name[0] - return self.form[field_name] - except (KeyError, IndexError): - pass - try: - return next(iter(self.form)) - except StopIteration: - return None - def _media(self): media = self.form.media for fs in self: diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index e35c7328f4..b2df1dcd3d 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -66,8 +66,14 @@ {% block submit_buttons_bottom %}{% submit_row %}{% endblock %} -{% if adminform.first_field and add %} - +{% if adminform and add %} + {% endif %} {# JavaScript for prepopulated fields #}