Tuesday, May 31, 2011

Passing parameters to form class

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment