Don't try too hard to directly link form to model.

For the attendance form, you might use a MultipleChoiceField
checkboxSelectMultiple widget, where the value of each choice is set
to the pk of the student model.   You should get a list of id's that
were checked when the form gets submitted.

Something like this:

class Attendance(forms.Form):
    student_list = forms.ChoiceField()
    def __init__(self,*args,**kwargs):
        super(Attendance,self).__init__(*args,**kwargs)
 
self.fields['student_list'].widget=forms.CheckboxSelectMultiple(choices=[(s.id,s.name)
for s in Students.objects.all()])

    def get_headcount(self):
        """ This will return a with the pk of every student 'checked'
"""
        if self.is_valid():
            return self.clean_data['student_list']

So if you had choices ((1,'Bob'),(2,'Peggy'),(3,'Barney'))
and a person checked Bob and Barney, you'd get a list back:  [1,3]


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