Thanks, you are right. My generic form template accesses forms errors
and they get populated.

This is behavior seems a little strange but other way (errors being
populated only when is_valid is called) would have different
complications I guess.

FYI, in my blog app, a blog item has several entries (i.e. pages). A
user can start a new blog item and submit his entry at the same time,
or select an existing blog item and append a new page to that item,
all using the same form. This is what I am tring to do.

Thanks for the replies.



On Jun 27, 7:35 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Jun 27, 2008 at 12:10 PM, omat <[EMAIL PROTECTED]> wrote:
>
> > Thanks for the clarification.
>
> > Apparently my demo case of the problem was not appropriate, but my
> > real problem is still there.
>
> > I have 2 ModelForms that I want to receive data at a single form
> > submission.
>
> > item_form is required only if 'item' field of the entry_form is
> > empty.
>
> > So I build the logic in my view that handles the form as follows:
>
> > def form(request):
> > ...
> >    if request.method == 'POST':
> >        item_form = ItemForm(request.POST, instance=item)
> >        entry_form = EntryForm(request.POST, instance=entry)
> >        if entry_form.is_valid():
> >            e = entry_form.save(commit=False)
> >            e.user = request.user
> >            if not form.cleaned_data['item']:
> >                if item_form.is_valid():
> >                    e.item = item_form.save()
> >                else:
> >                    return render_to_response(...)
> >            e.save()
> >            return HttpResponseRedirect(...)
> >        else:
> >            return render_to_response('blog/form.html',
> >                                      {'entry_form': entry_form,
> >                                       'item_form': item_form,
>
> > context_instance=RequestContext(request))
>
> > But when I submit an invalid entry_form (i.e. nothing related to item
> > form is executed or accessed other then the initialization item_form =
> > ItemForm(request.POST, instance=item)) the item_form arrives at my
> > template with a filled errors dictionary.
>
> > Any opinions?
>
> item_form doesn't 'arrive at' your template with a filled in errors
> dictionary.  Rather, rendering of item_form checks for (accesses) the errors
> attribute, which triggers validation and populates the errors dictionary.
> If you ever (including during rendering in the template) attempt to access
> errors, errors gets populated.  So you need to change your logic so that you
> do not generate a form that will get validation errors in cases where you
> don't care to see those errors because of some other circumstance.  Sorry,
> it isn't quite clear to me what you are trying to do exactly so it's hard
> for me to be more specific as to recommendations.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to