Hi,
I have created a form class like this:
class VoteRadioForm(forms.Form):
choices =
forms.ModelChoiceField(queryset=Choice.objects.filter(poll__active=
True, poll__id = 2),
empty_label= None,
widget= forms.RadioSelect,
)
This class gives me dynamic number of entries for my form, based on
the poll_id. But as you may have already seen it, the poll__id is
hardcoded in this example. In order to pass different values to
poll__id, I tried to generated my choices element inside the __init__
method like this:
#choices =
forms.ModelChoiceField(queryset=Choice.objects.filter(poll__active=
True, poll__id = 2),
def __init__(self, pid = None, *args, **kwargs):
super(VoteRadioForm, self).__init__()
self.fields['ch'] =
forms.ModelChoiceField(queryset=Choice.objects.filter(poll__active=
True, poll__id = pid),
empty_label= None,
widget= forms.RadioSelect,
)
The first example(Hardcoded version) works perfectly fine. The second
example generates the form correctly, when I use:
form = VoteRadioForm(i)
However, when I try to validate the data and pass the request object
to it, it gives me the following error:
int() argument must be a string or a number, not 'QueryDict'
I even tried to add *args and **kwargs arguments when initializing my
class, just like this example:
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/
But, it doesn't make any difference.
I'm having Pythong 2.6.5 on my Arch Linux machine.
I was wondering if anyone has ever had such problem?
Thanks in advance