Yes, you will want to do this within the __init__ method. Run the super class's init method first so that everything's initialized as normal.
Then you will have to grab the field for that instance within the __init__ method (self.fields['vaihtoehdot']) and set the choices property for it. On May 31, 3:09 am, skyde <madpoe...@gmail.com> wrote: > Hello, > > I've hit a brick wall while trying to create dynamic forms. > Basically I am trying to give parameter to a class form and then based > on that do a multiple choice questionaire. > > For example > > def somefunction(): > formi = someForm(ids='1') > > class someForm(forms.Form): > # get id from, use it to get some information from a model and then > based on that create a multiplechoice questionnaire. Or better yet do > the model querying in somefuntion and only pass the results to > someForm. > > ***** > Inside someForm I can create a tuple and then use this tuple to do a > MultipleChoiceField but I can't for the life of me understand how I > could parametrize this. > > So this works: > C = (('a','a'), ('b','b'), ('c','c'), ('d','d'),) > vaihtoehdot = forms.MultipleChoiceField(choices=C, > widget=forms.CheckboxSelectMultiple) > > but when I try to change the C to be dynamic I get an empty form. I've > tried fiddling with the __init__ function but to no avail. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.