On 11 Mar, 15:09, enquest <[EMAIL PROTECTED]> wrote:
> I'm using/learning the newforms... I got a model, in this model I have a
> choices list ( ('1', 'foo'), ('2', 'bar' ) that are reprensented as
> select box in the admin...
> However when I import this class to the newforms
> "forms.form_for_model(Gadget)" the choices arn't coming along and the
> field is reprented as a normal textfield... How come?

There is an open ticket about this argument: #3268.

I wrote a simple work-around:

choices = ( ('1', 'foo'), ('2', 'bar' ) )
myform = form_for_model(Gadget)
myform.fields['field_name'] = ChoiceField(choices=choices)

If you need to use form_for_instance remember to update
the initial value or you will not see the saved value pre-selected
on the select box.

choices = ( ('1', 'foo'), ('2', 'bar' ) )
myform = form_for_instance(Gadget_instance)
initial = myform.fields['field_name'].initial
myform.fields['field_name'] = ChoiceField(choices=choices,
initial=initial)

Hope this helps.

Massimiliano


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to