So I can create a queryset and pass its variable in the choices parameter to bind a modelchoicefield from a modelform to a particular iterable object? So then does this work only with modelforms or with any kind of form (one coded manually as well)? If I can do this with any form then where do I code the choices parameter? The only examples I've seen show it being coded using dictionaries containing hard-coded values and being coded as part of the form in question. Let me know as soon as you can. Thanks for the help.
On Jan 7, 11:02 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Friday, January 7, 2011 4:47:43 PM UTC, ShawnMilo wrote: > > > On 01/07/2011 11:33 AM, hank23 wrote: > > > I want to code a form which will have a choice field which I want to > > > have rendered as a dropdown box in my html file. How do I code the > > > choices parameter in the form definition to bind it to a column in one > > > of my data tables in my model? The documentation shows a few examples, > > > but nothing specifically for choice fields. Please explain. Thanks. > > > You have to use a ModelForm for this. > > > <snip> > > > Technically you can do it with a forms.Form, but you have to do the > > entire thing manually, which is a big waste. > > > <snip> > > > Shawn > > Er, no, both wrong. The source of choices for a field has nothing to do with > whether or not it's a modelform, and there is an easy built-in field class > for managing exactly what the OP requested: ModelChoiceField. This takes a > `queryset` parameter, which provides the data for the field choices. See the > docs:http://docs.djangoproject.com/en/1.2/ref/forms/fields/#modelchoicefield > -- > DR.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.