Ticket #10059: 10059-formfield_for_dbfield-r10365.diff

File 10059-formfield_for_dbfield-r10365.diff, 2.8 KB (added by Tai Lee, 16 years ago)

Patch created with svn diff with correct root.

  • django/contrib/admin/options.py

     
    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/tests.py

     
    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)
    101103
    102104class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
    103105    fixtures = ["admin-widgets-users.xml"]
     
    113115
    114116class AdminForeignKeyWidgetChangeList(DjangoTestCase):
    115117    fixtures = ["admin-widgets-users.xml"]
    116    
     118
    117119    def setUp(self):
    118120        self.client.login(username="super", password="secret")
    119    
     121
    120122    def tearDown(self):
    121123        self.client.logout()
    122    
     124
    123125    def test_changelist_foreignkey(self):
    124126        response = self.client.get('/widget_admin/admin_widgets/car/')
    125127        self.failUnless('/widget_admin/auth/user/add/' in response.content)
  • tests/regressiontests/admin_widgets/models.py

     
    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)
     
    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
Back to Top