Ticket #10059: 10059-formfield_for_dbfield-r10365.diff
File 10059-formfield_for_dbfield-r10365.diff, 2.8 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
107 107 108 108 # If we've got overrides for the formfield defined, use 'em. **kwargs 109 109 # 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) 113 114 114 115 # For any other type of field, just call its formfield() method. 115 116 return db_field.formfield(**kwargs) -
tests/regressiontests/admin_widgets/tests.py
98 98 self.assertFormfield(models.Member, 'gender', widgets.AdminRadioSelect, 99 99 radio_fields={'gender':admin.VERTICAL}) 100 100 101 def testInheritance(self): 102 self.assertFormfield(models.Album, 'backside_art', widgets.AdminFileWidget) 101 103 102 104 class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase): 103 105 fixtures = ["admin-widgets-users.xml"] … … 113 115 114 116 class AdminForeignKeyWidgetChangeList(DjangoTestCase): 115 117 fixtures = ["admin-widgets-users.xml"] 116 118 117 119 def setUp(self): 118 120 self.client.login(username="super", password="secret") 119 121 120 122 def tearDown(self): 121 123 self.client.logout() 122 124 123 125 def test_changelist_foreignkey(self): 124 126 response = self.client.get('/widget_admin/admin_widgets/car/') 125 127 self.failUnless('/widget_admin/auth/user/add/' in response.content) -
tests/regressiontests/admin_widgets/models.py
4 4 from django.core.files.storage import default_storage 5 5 from django.contrib.auth.models import User 6 6 7 class MyFileField(models.FileField): 8 pass 9 7 10 class Member(models.Model): 8 11 name = models.CharField(max_length=100) 9 12 birthdate = models.DateTimeField(blank=True, null=True) … … 23 26 band = models.ForeignKey(Band) 24 27 name = models.CharField(max_length=100) 25 28 cover_art = models.FileField(upload_to='albums') 29 backside_art = MyFileField(upload_to='albums_back', null=True) 26 30 27 31 def __unicode__(self): 28 32 return self.name