On 16 June 2010 13:53, George Sakkis <george.sak...@gmail.com> wrote: > On Jun 16, 4:22 pm, Peter Bengtsson <pete...@gmail.com> wrote: > >> 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! > > Not sure why this fails but regardless, it's not good to have part of > the validation logic outside the form. Instead define a clean() method > in the form, move there the "if not ..." part and check if it also > happens to solve the problem. >
That' why I used django-developers instead of django-users. Perhaps it's a bug and not a "user error". This functionality has changed in 1.2 so it's not solid what should work how. -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com fun crosstips.org -- 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.