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
-~----------~----~----~----~------~----~------~--~---

Reply via email to