Changes between Version 1 and Version 2 of CookBookNewFormsDynamicFields
- Timestamp:
- Dec 29, 2007, 9:17:45 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookNewFormsDynamicFields
v1 v2 21 21 age = forms.IntegerField() 22 22 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) 25 25 # now we add each question individually 26 for i in range(len(questions)):27 self.fields['question_%d' % i] = forms.ChoiceField(label=question s[i], ...)26 for i, question in enumerate(questions): 27 self.fields['question_%d' % i] = forms.ChoiceField(label=question, ...) 28 28 }}} 29 29