I have a modelform where I change the cleaned_data dict after I have run is_valid() and I'm not sure if this is the totally wrong way of doing things or if it's a bug. My code broke when I upgraded to 1.2 so it did work back in the 1.1 days.
# models.py class Person(models.Model): name = models.CharField() age = models.IntegerField() ... # forms.py class PersonForm(forms.ModelForm): class Meta: model = Person # views.py form = PersonForm(data=request.POST) form.fields['age'].required = False if form.is_valid(): if not form.cleaned_data['age']: form.cleaned_data['age'] = _fetch_age_by_name(form.cleaned_data['name']) assert form.cleaned_data['age'] person = form.save() # FAILS! Trying to run this fails with an IntegrityError or whatever it was called because it can't save the form when the age field's valid is None even though I have corrected the form data. It smells to me like modelforminstance.save() needs to reconstruct the instance from the cleaned_data again before committing. PS. The temporary solution for other people getting stuck on this is the following: person = form.save(commit=False) person.age = form.cleaned_data['age'] person.save() -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.