ModelChoiceField default value

1,240 views
Skip to first unread message

Rufman

unread,
Sep 17, 2007, 9:49:54 AM9/17/07
to Django users
how can i make one of the options in a select the default. (i
previously changed the select widget so that it only shows a selection
of options).

my code:
ModifyComment.base_fields['fk_bullet'] =
forms.ModelChoiceField(queryset=Bullet.objects.filter(fk_day=day_id))

i what one of the options in the querset to be the default or initial
value. using initial doesn't work with ModelChoiceFiel. Does anyone
know which other attribute i could use?

stephane

Richard Dahl

unread,
Sep 17, 2007, 11:40:03 AM9/17/07
to django...@googlegroups.com
initial works for me, however, you must set the initial by the id of the record not the instance, i.e.

forms.ModelChoiceField(queryset=Bullet.objects.filter(fk_day=day_id), initial = Bullet.objects.get(pk = day_id).id)

-richard
Reply all
Reply to author
Forward
0 new messages