Ian Ward's email:
first name at this domain
wardi on OFTC, freenode and github
Django's forms have fields like models, but you access them in a completely different way. I've found it hard to remember the correct way to access form field data properly, so this is a summary of the things I need to do with forms and how to do them. In particular these are useful in the form's __init__ method after calling super() to set up the form the way you want to.
UPDATE: There were a few mistakes in my earlier version of this post, now corrected.
aform['fieldname']fieldname, including the field and its dataaform.fields['fieldname'] or aform['fieldname'].fieldfieldnameaform.fields['fieldname'].initialaform.data['fieldname']fieldname UPDATE: this MultiValueDict includes the form prefix in its keys, indicating that it is likely not intended as a public interfaceaform['fieldname'].datafieldname, similar to: aform.data.get('fieldname', None) but it is safer because you get a KeyError if the field doesn't existaform.errors['fieldname']fieldname has no errorsaform['fieldname'].errorsfieldname, similar to: aform.errors.get('fieldname', []) but it is safer because you get a KeyError if the field doesn't existaform.cleaned_data['fieldname']fieldname's clean() method or calling the form's clean_fieldname() method. This dictionary doesn't exist if the form is unbound or invalid.del aform.fields['fieldname']And here are a couple Form field attributes I often need to modify:
aform.fields['choice_fieldname'].choices(id, display_text) tuplesaform.fields['modelchoice_fieldname'].queryset.choices will override thisIf you're updating your form field's widgets, this is useful too: (suggested by Graham Ullrich)
aform.fields['fieldname'].widgetaform.fields['date_transacted'].widget = widgets.AdminDateWidget()Tags: Django