headers=dict((str(c),c.label) for c in db.phmap)

On Aug 13, 3:05 am, dlin <dlin...@gmail.com> wrote:
> tks,  Massimo,  there is a typo "order" should be "orderby" in  your
> sample.
>
> Could I  just define the columns, and let headers automatic get from
> predefined labels?
> Because, in fact, I have more fields instead of two.
>
> On Aug 13, 3:23 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > words= db(db.phmap.id>0).select(limitby=(0,5),order='<random>')
> > table =SQLTABLE(words,
> >    headers={'phmap.F1':db.phmap.F1.label,phmap.F2:db.phmap.F2.label'},
> >    columns=['phmap.F1',phmap.F2'],
> >    truncate=32)
>
> > On Aug 13, 2:02 am, dlin <dlin...@gmail.com> wrote:
>
> > > I've a table with fields
> > > Field('F1', label='name')
> > > Field('F2', label='data')
> > > ....
> > > Field('F20', label='xxx')
>
> > > I wish use crud to display 5 random  rows of the table, and only
> > > display F1, F2.
>
> > > So, here is my  code:
>
> > > ids = [x.values()[0] for x in db().select(db.phmap.id).as_list()]
> > > idr = random.sample(ids, 5)
> > > words  = db(db.phmap.id.belongs(idr)).select(db.phmap.ALL)
>
> > > I want to display the words with only F1 and F2 fields.
> > > How could I display them by crud.select()?
> > > I want to be smarter to use the already defined labels in db.py,  but
> > > I don't know how to do it.

Reply via email to