Fixed #8194 (again): correctly focus on the first declared field in the admin. Thanks to fredbartle for catching my silly mistake the first time 'round.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8774 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2008-08-31 20:30:55 +00:00
parent 8b11341a9a
commit 4f5b0a321d
1 changed files with 8 additions and 3 deletions

View File

@ -20,9 +20,14 @@ class AdminForm(object):
yield Fieldset(self.form, name, **options) yield Fieldset(self.form, name, **options)
def first_field(self): def first_field(self):
if self.form._meta.fields is not None: try:
name = self.form._meta.fields[0] fieldset_name, fieldset_options = self.fieldsets[0]
return forms.BoundField(self.form, self.form.fields[name], name) field_name = fieldset_options['fields'][0]
if not isinstance(field_name, basestring):
field_name = field_name[0]
return self.form[field_name]
except (KeyError, IndexError):
pass
try: try:
return iter(self.form).next() return iter(self.form).next()
except StopIteration: except StopIteration: