On Jan 6, 2010, at 3:46 PM, Jeremy Dunck wrote:

> On Wed, Jan 6, 2010 at 3:56 PM, Joseph Kocherhans <jkocherh...@gmail.com> 
> wrote:
> ...
>>>> On Wed, Jan 6, 2010 at 12:49 PM, Simon Willison <si...@simonwillison.net> 
>>>> wrote:
> ...
>>>>> form = SecretQuestionForm( {"secret_question":"foo", "answer":"bar"} )
>>>>> if form.is_valid():
>>>>>    p = form.save(commit=False)
>>>>>    p.user = request.user
>>>>>    p.primary_contact = somecontact
>>>>>    p.save()
> ...
>> I had another idea that I think might work out. What if
>> ModelForm.validate() only validated fields on the form, like it worked
>> before the merge, and ModelForm.save() would automatically validate
>> the excluded fields, raising ValidationError if there was a problem?
>> Validation for each field would only happen once, it would accommodate
>> the commit=False idiom, and it would still ensure that the model
>> itself is validated in common usage.
> 
> Note that p in the example above is the unsaved model instance, not
> the ModelForm.  So to fix the idiom, the excluded field validation
> would need to be done on Model.save, not ModelForm.save, right?

Yeah, I think that must have been a typo in Joseph's mail. The way I read it 
that the model knows what fields it has already validated and the call to a 
Model.save would validate the rest.

Brian Rosner
http://oebfare.com
http://twitter.com/brosner

-- 
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.


Reply via email to