If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Add this to your model after instantiating auth,crud and mail.:

def store_in_db(db,settings,tablename):            
    validtypes = dict(string=type('t'),integer=type(3),double=type(3.0),boolean=type(True))    
    def get_dbtype(f,d):
        for k,v in validtypes.items():
            if v==type(d[f]): return k
        return 'string'    
    fields = [db.Field(f,get_dbtype(f,settings)) for f in settings if type(settings[f]) in validtypes.values()]
    db.define_table(tablename,*fields)

    if db(db[tablename].id>0).count() == 0:
        vals = dict([(k.name,settings[k.name]) for k in fields])
        db[tablename].insert(**vals)

    for k,v in db().select(db[tablename].ALL).first().items(): settings[k] = v

Now tell it to save your crud settings in the database:

store_in_db(db,crud.settings,'crud_settings')

alt text

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere