Ticket #10059: admin-widgets.2.diff

File admin-widgets.2.diff, 3.0 KB (added by Alex Gaynor, 16 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 8cc27c5..78be4ad 100644
    a b class BaseModelAdmin(object):  
    107107
    108108        # If we've got overrides for the formfield defined, use 'em. **kwargs
    109109        # passed to formfield_for_dbfield override the defaults.
    110         if db_field.__class__ in self.formfield_overrides:
    111             kwargs = dict(self.formfield_overrides[db_field.__class__], **kwargs)
    112             return db_field.formfield(**kwargs)
     110        for klass in db_field.__class__.mro():
     111            if klass in self.formfield_overrides:
     112                kwargs = dict(self.formfield_overrides[klass], **kwargs)
     113                return db_field.formfield(**kwargs)
    113114
    114115        # For any other type of field, just call its formfield() method.
    115116        return db_field.formfield(**kwargs)
  • tests/regressiontests/admin_widgets/models.py

    diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
    index 1ba759b..66d30bc 100644
    a b from django.db import models  
    44from django.core.files.storage import default_storage
    55from django.contrib.auth.models import User
    66
     7class MyFileField(models.FileField):
     8    pass
     9
    710class Member(models.Model):
    811    name = models.CharField(max_length=100)
    912    birthdate = models.DateTimeField(blank=True, null=True)
    class Album(models.Model):  
    2326    band = models.ForeignKey(Band)
    2427    name = models.CharField(max_length=100)
    2528    cover_art = models.FileField(upload_to='albums')
     29    backside_art = MyFileField(upload_to='albums_back', null=True)
    2630
    2731    def __unicode__(self):
    2832        return self.name
  • tests/regressiontests/admin_widgets/tests.py

    diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
    index c2b0403..1559d2b 100644
    a b class AdminFormfieldForDBFieldTests(TestCase):  
    9898        self.assertFormfield(models.Member, 'gender', widgets.AdminRadioSelect,
    9999                             radio_fields={'gender':admin.VERTICAL})
    100100
     101    def testInheritance(self):
     102        self.assertFormfield(models.Album, 'backside_art', widgets.AdminFileWidget)
     103
    101104
    102105class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
    103106    fixtures = ["admin-widgets-users.xml"]
    class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):  
    113116
    114117class AdminForeignKeyWidgetChangeList(DjangoTestCase):
    115118    fixtures = ["admin-widgets-users.xml"]
    116    
     119
    117120    def setUp(self):
    118121        self.client.login(username="super", password="secret")
    119    
     122
    120123    def tearDown(self):
    121124        self.client.logout()
    122    
     125
    123126    def test_changelist_foreignkey(self):
    124127        response = self.client.get('/widget_admin/admin_widgets/car/')
    125128        self.failUnless('/widget_admin/auth/user/add/' in response.content)
Back to Top