tags:

views:

18

answers:

1

HI!

I want to be able to select from something like this:
Let's say the number and student name, both in the same line and both will appear.
1 John
2 Marie
3 Jane
(..)
So what I've done in the forms is:

class StudentForm(forms.Form):
    std = tuple of number and name
    nbr = forms.ModelChoiceField(student, choices=std, widget=Select(), required=True) 

The view:

if request.method == 'POST':
    form_std = StudentForm(request.POST)
    if form_std.is_valid():
        std = form_std.cleaned_data['nbr']
        std_nr = std.number
        if std_nr:
            idt = std_nr
        return render_to_response('temp.html', {'form_std': form_std, 'idt': idt})

And the template:

<form action="" method="post">
    {% for field in form_std %}
        {{ field }}
    {% endfor %}

<input type="submit" value="Submit" />
</form> 

I'm getting this error:
TypeError: TypeError: init() got an unexpected keyword argument 'choices'

If someone could help me I would appreciate :)
Thanks

A: 

Solved!

If anyone is interested here goes the changes:

nbr = forms.ModelChoiceField(std, widget=Select(), required=True) 
nbr.choices = tuple number name
Pat