Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #10059: `ModelAdmin.formfield_for_dbfield` now handles custom `…

…Field` subclasses. Thanks, Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10454 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f55f2b9d74bf59d1b3ace5df5f498998eb62cb28 1 parent 6eaf154
@jacobian jacobian authored
View
7 django/contrib/admin/options.py
@@ -108,9 +108,10 @@ def formfield_for_dbfield(self, db_field, **kwargs):
# If we've got overrides for the formfield defined, use 'em. **kwargs
# passed to formfield_for_dbfield override the defaults.
- if db_field.__class__ in self.formfield_overrides:
- kwargs = dict(self.formfield_overrides[db_field.__class__], **kwargs)
- return db_field.formfield(**kwargs)
+ for klass in db_field.__class__.mro():
+ if klass in self.formfield_overrides:
+ kwargs = dict(self.formfield_overrides[klass], **kwargs)
+ return db_field.formfield(**kwargs)
# For any other type of field, just call its formfield() method.
return db_field.formfield(**kwargs)
View
4 tests/regressiontests/admin_widgets/models.py
@@ -4,6 +4,9 @@
from django.core.files.storage import default_storage
from django.contrib.auth.models import User
+class MyFileField(models.FileField):
+ pass
+
class Member(models.Model):
name = models.CharField(max_length=100)
birthdate = models.DateTimeField(blank=True, null=True)
@@ -23,6 +26,7 @@ class Album(models.Model):
band = models.ForeignKey(Band)
name = models.CharField(max_length=100)
cover_art = models.FileField(upload_to='albums')
+ backside_art = MyFileField(upload_to='albums_back', null=True)
def __unicode__(self):
return self.name
View
8 tests/regressiontests/admin_widgets/tests.py
@@ -98,6 +98,8 @@ def testChoicesWithRadioFields(self):
self.assertFormfield(models.Member, 'gender', widgets.AdminRadioSelect,
radio_fields={'gender':admin.VERTICAL})
+ def testInheritance(self):
+ self.assertFormfield(models.Album, 'backside_art', widgets.AdminFileWidget)
class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
fixtures = ["admin-widgets-users.xml"]
@@ -113,13 +115,13 @@ def testFilterChoicesByRequestUser(self):
class AdminForeignKeyWidgetChangeList(DjangoTestCase):
fixtures = ["admin-widgets-users.xml"]
-
+
def setUp(self):
self.client.login(username="super", password="secret")
-
+
def tearDown(self):
self.client.logout()
-
+
def test_changelist_foreignkey(self):
response = self.client.get('/widget_admin/admin_widgets/car/')
self.failUnless('/widget_admin/auth/user/add/' in response.content)
Please sign in to comment.
Something went wrong with that request. Please try again.