Hi Randall,

Can you open a trac ticket so that I can consider this a little later?
Right now, I'm focusing on the things I need to do to get 0.9 out the
door and this one can wait a bit.

Note, that you don't need to change formmaker.py to do this. In Python
2.4 syntax (which is a lot more pleasant) and in any module of your
own code, you can do this:

from turbogears.fastdata import formmaker

@formmaker.column_widget.when("isinstance(column, SOKeyCol)")
def column_widget_fk_col(column):
   parms = column_parms(column)
   fk_class_name = column.foreignKey
   fk_class = sqlobject.classregistry.findClass(fk_class_name)
   fk_class_data = fk_class.select()
   if hasattr(fk_class, 'option_name'):
       options = [[rset.id, rset.option_name] for rset in
fk_class_data]
       return widgets.SelectField(validator=None, options=options,
**parms)
   else:
       return widgets.TextField(validator=None, **parms)

On 1/5/06, Randall <[EMAIL PROTECTED]> wrote:
>
> Forgive me for cross posting, but this really belongs under
> "sqlwidgets".  I think sqlwidgets rocks!
>
> Check this out.  I added this to formmaker.py  It creates a select box
> if your SQLObject class has an attribute named 'option_name'.
> option_name should be configurable.  Really cool I think!
>
> # Do this at the top.
> import sqlobject
>
> # Added to handle foreign keys.
> def column_widget_fk_col(column):
>     parms = column_parms(column)
>     fk_class_name = column.foreignKey
>     fk_class = sqlobject.classregistry.findClass(fk_class_name)
>     fk_class_data = fk_class.select()
>     if hasattr(fk_class, 'option_name'):
>         options = [[rset.id, rset.option_name] for rset in
> fk_class_data]
>         return widgets.SelectField(validator=None, options=options,
> **parms)
>     else:
>         return widgets.TextField(validator=None, **parms)
> column_widget_fk_col = column_widget.when(
>     "isinstance(column, col.SOKeyCol)")(column_widget_fk_col)
>
>


--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Reply via email to