Changes between Version 1 and Version 2 of CookBookNewFormsDynamicFields


Ignore:
Timestamp:
Dec 29, 2007, 9:17:45 AM (16 years ago)
Author:
Todd O'Bryan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBookNewFormsDynamicFields

    v1 v2  
    2121    age = forms.IntegerField()
    2222
    23     def __init__(questions, *args, **kwargs):
    24         super(Survey, self).__init__(*args, **kwargs)
     23    def __init__(self, questions, *args, **kwargs):
     24        super(Survey, self).__init__(self, *args, **kwargs)
    2525        # now we add each question individually
    26         for i in range(len(questions)):
    27              self.fields['question_%d' % i] = forms.ChoiceField(label=questions[i], ...)
     26        for i, question in enumerate(questions):
     27             self.fields['question_%d' % i] = forms.ChoiceField(label=question, ...)
    2828}}}
    2929
Back to Top