I found we can just JOIN the table and specify the fields you want to
display. It's nice if grid does it automatically but this is easy
enough.


def admin():
    db.Product.id.readable = False
    query = db.Product.Model_ID == db.Model.id
    products =
SQLFORM.grid(query,create=False,editable=False,deletable=False,
paginate=10,
 
fields=[db.Product.id 
,db.Model.Name,db.Product.Part_Number,db.Product.List_Price,
                db.Product.Weight])
    return dict(products = products)

On Nov 15, 8:29 am, Omi Chiba <[email protected]> wrote:
> Jim,
>
> Yeah, that was first thing I tried but grid doesn't understand it like
> form.
>
> On Nov 14, 5:40 pm, Jim Steil <[email protected]> wrote:
>
>
>
>
>
>
>
> > Here's what I would do.
>
> > (not tested)
>
> > db.define_table('Model',
> >      Field('Name'),
> >      Field('Unit'),
> >      format='%(name)s')
>
> >      -Jim
>
> > On 11/14/2011 4:55 PM, Omi Chiba wrote:
>
> > > I want to show the reference field value ('Name' in Model table) on
> > > the grid instead of the original value (Model_ID in Product table).
>
> > > Is there easy way to do it ?
>
> > > Controller
> > > -----------------------
> > > def admin():
> > >      db.Product.id.readable = False
> > >      products =
> > > SQLFORM.grid(db.Product,create=False,editable=False,deletable=False,
> > > paginate=10)
> > >      return dict(products = products)
> > > -----------------------------------------------------
>
> > > Model
> > > --------------------------
> > > db.define_table('Model',
> > >      Field('Name'),
> > >      Field('Unit'))
>
> > > db.define_table('Product',
> > >      Field('Part_Number',label='Part Number'),
> > >      Field('Model_ID', db.Model ,label='Model Number'),
> > >      Field('List_Price', 'decimal(13,2)' ,label='List Price'),
> > >      Field('FOB', 'decimal(13,2)' ,label='FOB'),
> > >      Field('Weight', 'decimal(13,2)' ,label='Weight'))
> > > --------------------------------------------------

Reply via email to