On Jan 6, 2010, at 3:59 PM, Joseph Kocherhans wrote: > On Wed, Jan 6, 2010 at 4:46 PM, Jeremy Dunck <jdu...@gmail.com> 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? > > Ugh. Yes it would. I did mean ModelForm.save(), but as you've pointed > out, that won't work (at least for the idiom). One of the early > decisions was that Model.save() would never trigger validation for > backwards compatibility purposes. Maybe something from the idea is > salvageable, but it won't work as I presented it. I think having the > model track which validators have been run and which haven't is a > non-starter. That's something Honza actively avoided in the design.
Saw this after my e-mails. This does present an issue. For sake of backwards compatibility it would seem that the second step of validation could just be done by the developer? This is mostly to prevent double validation, but also maintain compatibility with the Django idiom. 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.