Django: How to iterate over formsets and access cleaned data?

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-09T04:53:22Z Indexed on 2010/03/09 5:06 UTC
Read the original article Hit count: 311

Filed under:
|

What if I want to do something with my formset other than immediately saving it?

How can I do this?

        for form in vehicles_formset.forms:
            listing.id = None
            listing.vehicle_year = form.cleaned_data['year']
            listing.vehicle_make = form.cleaned_data['make']
            listing.vehicle_model = form.cleaned_data['model']
            listing.vin = form.cleaned_data['vin']
            listing.vehicle_runs = form.cleaned_data['runs']
            listing.vehicle_convertible = form.cleaned_data['convertible']
            listing.vehicle_modified = form.cleaned_data['modified']
            listing.save()

(Thus creating multiple listings) Apparently cleaned_data does not exist. There's a bunch of stuff in the data dict like form-0-year but it's pretty useless to me like that.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-formsets