this is my form+formset and the validation/error display works for both
at the same time.
maybe you can get yours working by comparing it


    def myform(request):
        idea_form =  ProjectideaForm
        activity_formset = inlineformset_factory(Projectidea, Activity,
    extra=5)
        if request.method == 'POST': # If the form has been submitted...
            form    = idea_form(request.POST)
            formset = activity_formset(request.POST,
    instance=Projectidea()) # A form bound to the POST data
            if form.is_valid() and formset.is_valid(): # All validation
    rules pass
                new_idea = form.save()
                formset_models = formset.save(commit=False)
                for f in formset_models:
                    f.projectidea = new_idea
                    f.save()
                return HttpResponseRedirect(new_idea.get_absolute_url())
    # Redirect after POST        
        else:
               form    = idea_form()
               formset = activity_formset()
        return render_to_response('fslform/fslform.html',
                                  {'form'   : form, 'formset': formset,},
                                  context_instance=RequestContext(request))





cerberos wrote:
> I'm building a library system and have models Member, Loan and
> LoanItem (relationships as you'd expect), and an inline formset to
> enter a new loan (Loan and LoanItems).
>
> A member can borrow up to 6 books at a time, so my form contains 7
> individual forms (1 loan and 6 loan items), I need to get the member
> from the loan and the number of loan items from the loan items forms
> then raise an error if the items already loaned + the number of new
> loan items entered is greater than 6.
>
> I can raise errors based on the form or the formset but not both
> together, is this possible? What do I subclass to add the custom clean
> method?
>
>
> Here's my unfinished view
>
>
> def loan_add_form(request,template_name='resources/
> loan_add_form.html'):
>
>     loan = Loan()
>     LoanItemFormset = inlineformset_factory
> (Loan,LoanItem,formset=LoanItemBaseModelFormSet,can_delete=False,extra=6,exclude='date_returned')
>
>     if request.method == 'POST':
>
>         loan_form = forms.LoanForm(request.POST,instance=loan)
>         loan_item_formset = LoanItemFormset
> (request.POST,request.FILES,instance=loan)
>
>         if loan_form.is_valid() and loan_item_formset.is_valid():
>             loan_form.save()
>             loan_item_formset.save()
>
> #            request.user.message_set.create(message="Confirmation
> message.")
> #            return HttpResponseRedirect('/somepath')
>
>     else:
>         loan_form = forms.LoanForm(instance=loan)
>         loan_item_formset = LoanItemFormset(instance=loan)
>
>     context = {
>         'loan_form': loan_form,
>         'loan_item_formset': loan_item_formset,
>     }
>
>     return render_to_response(template_name, context,
> context_instance=RequestContext(request))
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>
>   

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.


Reply via email to