On Fri, Feb 20, 2009 at 1:21 PM, flagg <ianand0...@gmail.com> wrote: > > Ok this is driving me nuts. I have two form objects that manipulate > two models. I am trying to run the is_valid() method on both and then > save the form data to the DB. > > def all_valid(form1, form2): > return form1.is_valid() and form2.is_valid() > > def addorder(request): > today = date.today() > if request.method == 'POST': > orderform = OrderForm(request.POST, instance=Order(), > prefix="order") > equipform = EquipmentForm(request.POST, instance=Equipment(), > prefix="equipment") > if all_valid(equipform, orderform) == True: > orderform.save() > equipform.save() > return HttpResponseRedirect('/inventory/') > else: > orderform = OrderForm(initial={'orderdate': today.strftime('%Y- > %m-%d')}, instance=Order(), prefix="order") > equipform = EquipmentForm(instance=Equipment(), > prefix="equipment") > > return render_to_response('order_form.html', { 'orderform': > orderform, 'equipform': equipform }) > > If I only run is_valid on one form it adds the record correctly. But > when I add the second form validation check it fails. >
It fails where, exactly? And how, exactly? 'Fails' meaning the the records aren't added and you aren't redirected to /inventory/ but rather get the form submission page redisplayed? If so, does the redisplay include any errors on any of the form fields? 'Fails' meaning an exception is thrown? 'Fails' meaning...? It would really help people help you if you were more specific about what 'fails' means. It also isn't entirely clear what you mean when you say if you run is_valid on one form (which one? does it matter which one? or no, either one works individually but just not both together?) 'the record' is added correctly -- the code you post appears to add 2 records, so presumably the code that works is a bit more different than just truncating the return line from all_valid to not call is_valid on the 2nd form? Exact details of the difference between the code that works and the code that fails might help people spot the significant difference. As it seems you have only posted the non-working version, people have to imagine what the working version looks like, which again makes it harder to try to help. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---