If any two inputs have the same name, both values are returned in a
list ala [request.POST.getlist('score')] With the checkboxes it's easy
to identify by value. I assume you might be able to figure out where
that score belongs by order, but I'm not sure order is guaranteed.

I think if it were me I'd build a form builder function, metaclass, or
do it in __init__.  Probably the easiest is passing in an argument to
__init__ , that gives enough information to build the form.

class Foo(forms.Form):
    fail_them_all = forms.ChoiceField(choices=((0,'Yes'),(1,'Yes')))
    def __init__(self,student_list,*args, ** krwargs):
         super(Foo,self).__init__(*args,**kwargs):
         self.dynfields = {}
         # generate fields
         for s in student_list:
              fn = "student_%s" % s.id
              self.fields[fn] = forms.CharField()
              self.dynfields[fn] = s.id

     def save(self):
           # do non dynamic saves here
           # now take care of the generated fields
           for fn in self.dynfields:
               score =
Score(student=self.dynfields[fn],score=self.clean_data[fn])
               score.save()


This is assuming you 'know' the list of students to pass in for when
the data is posted (maybe a hidden field). If you can't know that,
then you'd have to do some regexp matching on the field names to
extract enough information (just like the django urls work).  That
would also get rid of the extra dynfields dict, but I'm guessing would
be slower.



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