Django forms are just form elements, not the whole form.  The easy
approach is to split your form into several django forms, and process
them separately in the view.  If you have multiple instances of the
same form class you can keep them identified by using a prefix when
you instantiate each (you'll have to come up with your own mechanism
for generating the prefixes, you might use primary key):

http://www.djangoproject.com/documentation/newforms/#prefixes-for-forms

This is an example of prefixing (untested, and incomplete),

def make_student_forms_for(teacher,post=None):
    form_list=[]
    for s in teacher.student_set.all():
        form_list.append(StudentForm(post,
                                     initial=s.__dict__.copy(),
                                     prefix=s._get_pk_val()))
    return form_list

def student_list(request,teacher_id):
    teacher = Teacher.objects.get(pk=teacher_id)
    if request.POST:
        errors=False
        form_list = make_student_forms_for(teacher,request.POST)
        for form in form_list:
            if form.is_valid():
                form.save() # you write this!
           else:
                errors=True
           if not errors:
                return HttpResponseRedirect(somewhere)
    else:
        form_list = make_student_forms_for(teacher)
    return render_to_response('students/multiedit.html',
                       {'forms':form_list,
                       'teacher':teacher})

--~--~---------~--~----~------------~-------~--~----~
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