Overriding initial value in ModelForm

Posted by schneck on Stack Overflow See other posts from Stack Overflow or by schneck
Published on 2010-06-07T10:04:35Z Indexed on 2010/06/07 10:22 UTC
Read the original article Hit count: 204

Filed under:
|

Hi,

in my Django (1.2) project, I want to prepopulate a field in a modelform, but my new value is ignored. This is the snippet:

class ArtefactForm(ModelForm):
    material = CharField(widget=AutoCompleteWidget('material', force_selection=False))

    def __init__(self, *args, **kwargs):
        super(ArtefactForm, self).__init__(*args, **kwargs)
        self.fields['material'].initial = 'Test'

I also tried with self.base_fields, but no effect: there is always the database-value displaying in the form. Any ideas?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-forms