Changes between Version 19 and Version 20 of NewformsHOWTO


Ignore:
Timestamp:
02/27/2008 09:14:37 AM (8 years ago)
Author:
Lllama <f.ingram.lists@…>
Comment:

Change overriding of formfields to use super

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v19 v20  
    9797        if isinstance(db_field, models.TextField):
    9898            return forms.CharField(widget=forms.Textarea(attrs={'cols': 130, 'rows':30, 'class': 'docx'}))
    99         return db_field.formfield(**kwargs)
     99        return super(MyOtherModelInline, self).formfield_for_dbfield(db_field, **kwargs)
    100100}}}
    101101
     
    105105#!python
    106106    def formfield_for_dbfield(self, db_field, **kwargs):
    107         field = db_field.formfield(**kwargs) # Get the default field
     107        field = super(MyModel, self).formfield_for_db_field(db_field, **kwargs) # Get the default field
    108108        if db_field.name == "the_field_I_want_to_change": # Check if it's the one you want
    109             field.widget.attrs['class'] = "my_new_class" # Poke in the new attrs
     109            field.widget.attrs['class'] = "my_new_class" # Poke in the new
    110110        return field
    111111}}}
Back to Top