On Jul 18, 2006, at 9:46 PM, Donald Ball wrote:

>
> Sorry for the deluge of questions, I'm trying to master everything
> turbogears has to offer. I'm playing with form widgets now, very nice.
> It's unclear to me, however, how to initialize a form with values  
> from a
> model object. For instance, I'm working on using the form widgets  
> to build
> an admin controller to manage identity objects. I have an editUser  
> method
> which displays forms to add and edit users:
>
>      @expose(template=".templates.form")
>      def editUser(self, tg_errors=None, *args, **params):
>          if tg_errors:
>              turbogears.flash("Error on form: " + str(tg_errors))
>          return dict(form=user_form, action='saveUser', title='Edit  
> User')
>
> the obvious next step will be to add logic to load a User object  
> based on
> the params and use that to populate the form. This must be fairly  
> easy,
> but it's sadly unclear to me. Any help?

You can pass any instance as a value to the form and it's attributes  
will be fetched as values for the child widgets (the form's fields).  
Something like:

class User(SQLObject):
        name = StringCol(alternateId=True)
        age = IntCol()

class MyForm(TableForm):
        fields = [
                TextField('name'),
                TextField('age'),
                ]

form = MyForm()
form.display(User.byName('alberto'))

HTH,
Alberto

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

Reply via email to