Choice Field Help

5 views
Skip to first unread message

jimfmunro

unread,
Jan 10, 2013, 5:07:00 PM1/10/13
to front-ran...@googlegroups.com

if I want to set up a choices field values in a view, 

I am doing 

## forms.py

class MyFormClass(forms.Form):

users = form.ChoicesField()

## views.py

my_choices = [(c.id, c.username) for c in users] 

my_form = MyFormClass() 

form.fields['users'].choices 

# pass it back to the template

Is this a good way to do this?

The form displays my choices in the correct way, seemingly.

I see <option value="3">jim</option> on the form control, but when I submit the form I get the following validation error:

Select a valid choice. 3 is not one of the available choices.

Any suggestions on debugging this?

Thanks!


Reply all
Reply to author
Forward
0 new messages