views:

1939

answers:

1

How can i clean and modify data from a form in django. I would like to define it on a per field basis for each model, much like using ModelForms.

What I want to achieve is automatically remove leading and trailing spaces from defined fields, or turn a title (from one field) into a slug (which would be another field).

+5  A: 

You can define clean_FIELD_NAME() methods which can validate and alter data, as documented here: http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation

Alex Gaynor
Also the overall clean() method of the Form.
S.Lott