Based on what you described as your intent, have you looked at ModelChoiceField? You could create a new table, e.g. ProductOptions, that has a foreign key to your Product table. In your form class you can then pass a queryset into the ModelChoiceField that selects only the options for that product, and if necessary even filter out any options that aren't available - assuming your ProductOption table had a quantity field.
If you have many products that share a common set of options (e.g., all shirts have S, M, L, XL, etc.) you might design the tables a little differently, but ultimately a ModelChoiceField can be passed any queryset that filters the correct options. If you prefer to store each product's options as a comma separated field, you can still do what was suggested previously and just pass the choices into the init method of the form. Regarding your issue of needing an iterable - as was stated by Steve Holden if you have a method that produces the choices, then you want to call that method, e.g., choices=foo.create_choices(), not choices=foo.create_choices. On Tue, Aug 3, 2010 at 2:29 PM, shofty <m...@shofty.me> wrote: > cheers for reading Steve. > > I've been through the documentation again and it definitely states > that the widget wants an iterable. so i dont think im going to be able > to do what i wanted to do, need another approach. > > Matt > > On 3 Aug, 16:15, Steve Holden <holden...@gmail.com> wrote: > > On 8/3/2010 11:12 AM, shofty wrote: > > > > > Steve, > > > > > the choices are different for each product in the shop. > > > some choices are clothing sizes, some physical sizes etc. > > > > > So with that in mind i could go with a bunch of choices hooked up to a > > > choices field if i can tell the form which choice field to use based > > > around the product attribute stored. > > > > > but what if im not the shop admin? > > > in that case i'd have to amend the code every time something goes out > > > of stock in a certain size. > > > > > so i came upon the plan to have a boolean denote whether or not the > > > object has a size option and if so store the options in the model so > > > that it could be amended in the admin pages. then draw a select at > > > runtime with the right options in it. > > > > > thanks for the other pointers, i had an idea the function wasn't right > > > and indeed it isn't going to work at all since the widget won't allow > > > a callable. > > > > > i'll try turning that function into a method on the form and see if it > > > won't work that way > > > > Good stuff. This is a pretty helpful group, so do post again when you > > have further issues. Nobody gets it right the first time ... > > > > regards > > Steve > > -- > 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<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- 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.