Commit f55f2b9d authored by Jacob Kaplan-Moss's avatar Jacob Kaplan-Moss
Browse files

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

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
parent 6eaf154a
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -108,8 +108,9 @@ class BaseModelAdmin(object):

        # 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)
        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.
+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@ from django.db import models
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
+5 −3
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ class AdminFormfieldForDBFieldTests(TestCase):
        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"]