Mistake in my first paragraph table why not use
On Mon, Sep 12, 2011 at 4:35 PM, Richard Vézina <ml.richard.vez...@gmail.com> wrote: > It seems to me correct except for the view, if you want a table not use : > > Controller : > table = crud.select(db.data) > return dict(table=table) > > > > View : > {{=table}} > > > You can also make your select constraint in the controller : > > query = (db.data.FIELD == SOMETHING) > > table = crud.select(db.data, query=query) > > > http://www.web2py.com/book/default/chapter/07?search=crud.select#CRUD > > Richard > > On Mon, Sep 12, 2011 at 4:27 PM, Chris Rowson > <christopherrow...@gmail.com> wrote: >> I have two tables: >> ----------------------------------------- >> db.define_table('providers', >> Field('name'), >> Field('email'), >> Field('tel') >> >> db.define_table('data', >> Field('dataowner', db.auth_user, default=auth.user_id, >> writable=False, readable=False), #this points at the auth user >> Field('provider', db.providers), >> Field('speed', 'integer') >> >> db.data.provider.requires=IS_IN_DB(db, 'providers.id','providers.name') >> --------------------------------------------- >> >> My controller has this code >> >> def map(): >> response.view="map.html" >> # selects the data postcode fields from the database >> # returns an interable object >> rows=db().select(db.data.lon, db.data.lat, db.data.provider) >> return dict(rows=rows) >> >> ----------------------------------------------- >> >> And my view this code >> >> {{for i,row in enumerate(rows):}}{{if not i==0:}},{{pass}} >> { lat: {{=row.lat}}, lng: {{=row.lon}}, name: "{{=row.provider.name}}" } >> {{pass}} >> >> ------------------------------------------------ >> As you can see, the provider field in the data table stores the provider id. >> >> I'm confused! >> >> Although this does work I don't know why!, is it the correct way to >> reference the name field from the providers table? >> >> Thanks! >> >> Chris >> >