Sweet. Thanks. I thought about something along those lines before
reading the response, but I would have passed a call to the function,
get_item_list(), rather than the fuction itself, get_item_list. I
need to research why that works. Thanks again, I'll do my reading.
On Feb 26, 1:21 am, "Ian Wilson" <[EMAIL PROTECTED]> wrote:
> You can either assign a callable to options that returns an update to
> date list of items or pass them in at display time. To use a callable
> do something like this:
>
> #Define the callable somewhere
> def get_item_list():
> return [(item.id, item.name) for item in
> model.Item.select(model.Item.q.active == True, orderBy='name')]
>
> #Define the items like this
> items = widgets.CheckBoxList(validator=validators.Int(),
> options=get_item_list)
>
> -Ian
>
> On 2/23/07, Carlos Hanson <[EMAIL PROTECTED]> wrote:
>
>
>
> > Greetings,
>
> > I have created a couple widgets: ItemFields and MenuFields. Both
> > extend WidgetsList. I use both in a TableForm. The ItemFields are
> > used to create an Item, while the MenuFields are used to create a
> > Menu. In my MenuFields class, I select all the Items
> > (model.Item.select()) and use the results to populate a CheckBoxList.
>
> > The problem I have is after adding a new Item, it does not show in the
> > TableForm made from the MenuFields. How do I ensure the CheckBoxList
> > in my MenuFields is always up to date.
>
> > Thanks in advance. My code follows:
>
> > class ItemFields(widgets.WidgetsList):
> > """Form fields for creating an Item."""
>
> > name = widgets.TextField(validator=validators.NotEmpty())
> > active = widgets.CheckBox(attrs=dict(checked=True),
> > help_text='If unchecked, it is unavailable to new menus.')
>
> > class MenuFields(widgets.WidgetsList):
> > """Form fields for creating a Menu."""
>
> > item_list = []
> > all_items = model.Item.select(model.Item.q.active == True,
> > orderBy='name')
> > for item in list(all_items):
> > item_list.append((item.id, item.name))
>
> > date = widgets.CalendarDatePicker("date")
> > items = widgets.CheckBoxList(validator=validators.Int(),
> > options=item_list)
>
> > item_form = widgets.TableForm(
> > fields=ItemFields(), action='save', submit_text='Add Item')
> > menu_form = widgets.TableForm(
> > fields=MenuFields(), action='save', submit_text='Add Menu')
>
> > class Menu(controllers.Controller):
> > @expose(template='.templates.add')
> > def add(self, tg_errors=None):
> > """Show the Menu form."""
>
> > if tg_errors:
> > flash('There was a problem with the form!')
> > return dict(form=menu_form)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---