To answer your first question I will illustrate it with an example:
#models
db.define_table('person',
Field('name'),
Field('age','integer'),
format='%(name)s'
)
db.define_table('dog',
Field('name'),
Field('owner','reference person'),
format='%(name)s'
)
#controller
def build_new_table():
# drop table if already there
if 'newtable' in db.tables:
db.newtable.drop()
# create table
db.define_table('newtable',
# first new field same as person.name
db.person.name,
# rename second since fields need distinct names
Field('dog_name',type=db.dog.name.type,length=db.dog.name.length)
)
# SELECT person.name, dog.name FROM person JOIN dog ON
(person.id=dog.owner)
rr=db(db.person.id==db.dog.owner).select(db.person.name,db.dog.name)
# add records to newtable
for r in rr:
db.newtable.insert(name=r.person.name,dog_name=r.dog.name)
db.commit()
For more info on queries see chapter 6 of the book:
http://web2py.com/book/default/chapter/06
To show the records you could use powertable plugin by Bruno, who
recently won the second web2py app exhibition.
But a simple SQLTABLE will do too.
On Jan 29, 10:07 am, vortex wrote:
> Because I have a controller that presents data for a table. So to
> present data which is a join of several tables, I would build a table
> and then use that same controller. Where can I find more information
> on how to make more complex queries and presenting data with web2py?
>