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?
--
omat
On Jun 27, 6:47 pm, Arien <[EMAIL PROTECTED]> wrote:
> On Fri, Jun 27, 2008 at 10:39 AM, omat <[EMAIL PROTECTED]> wrote:
>
> > At the instant I initialize my form, the errors dict is filled,
> > although the documentation says, the validation happens after form
> > instance's is_valid() method is called.
>
> > [example snipped]
>
> > Is the documention or the behavior wrong?
>
> Neither. As explained in the docs "the form's data will be validated
> the first time either you call is_valid() or access errors",
> seehttp://www.djangoproject.com/documentation/newforms/#using-forms-to-v...
>
> Arien
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---