db.define_table('meta',Field('name'))
for row in db(db.meta).select():
db.define_table(row.name,Field('fieldname'))
def dynamically_add_new_table(db,name):
db.meta.insert(name=name)
db.define_table(name,Field('fieldname'))
then you call the function dynamically_add_new_table for the value of
name that you need.
On Mar 11, 8:55 am, Jose <[email protected]> wrote:
> Hi everyone,
>
> I'm using PostgreSQL + postgis.
>
> In web2py, in the model, define the table localidades:
>
> tb_localidades = db.define_table('localidades',
> Field('nombre', length=100),
> ...
> Field('alias', length=50, comment='Un único nombre'),
> ...
> Field('datos', 'upload', autodelete=True, label='Datos
> (shapefile)', comment='Usar los tres archivos (.shp, .shx y .dbf)
> zipeados'),
> ...
> format='%(nombre)s'
> )
>
> Each row in localidades has an associated shapefile [1], which is
> uploaded to the server. This shapefile is migrated to the database
> with the command shp2pgsql (all this happens on the server).
>
> alias field is used as the name of the table (with geographical
> attributes) migrated.
>
> I have 2 problems:
>
> 1) The only connection between the localidad and the geographical
> table migrated, is the field alias. This somehow I could fix by
> altering the table or sql that generates the table.
>
> 2) This is to me more difficult to solve. What I want is that the new
> geographical table is included in the model dynamically. This table
> has no fixed structure is defined by the shapefile associated with the
> localidad.
>
> Is there any way to include every geography table associated to the
> localidad, within the model (dynamically)?
>
> Jose
>
> [1]http://en.wikipedia.org/wiki/Shapefile