After the

http://www.thadeusb.com/weblog/2009/12/31/web2py_virtualfields_as_an_orm_an_sqlalchemy_approach

webpage I made something like:
--- cut ---
db.define_table( 'web_sites',
                                                                Field( 
'web_id', db.web,
                                                                                
        label = T( 'Web config' ),
                                                                                
        requires = IS_IN_DB( db, 'web.id', '%(name)s' ) ),
                                                                Field( 'name', 
'string',
                                                                                
        label = T( 'Name' ),
                                                                                
        requires = [IS_NOT_EMPTY()] ),
                                                                Field( 'txt', 
'text',
                                                                                
        label = T( 'Config file' ),
                                                                                
        requires = [IS_NOT_EMPTY()] ),
                                                                Field( 
'weight', 'integer',
                                                                                
        label = T( 'Weight' ),
                                                                                
        requires = [IS_NOT_EMPTY()] ),
                                                                Field( 
'active', 'boolean',
                                                                                
        label = T( 'Active' ),
                                                                                
        default = True,
                                                                                
        ),
                                                                Field( 
'modified', 'boolean',
                                                                                
        label = T( 'Modified' ),
                                                                                
        default = True,
                                                                                
        writable = False,
                                                                                
        readable = False,
                                                                                
        ),
 )

# computing ServerNames and ServerAliases
##########################################
class web_sites_extra():
        def servername( self ):
                def lzy(  ):
                        x = 'sfjha'
                        return x
        return lzy


db.web_sites.virtualfields.append( web_sites_extra() )
--- cut ---

In the view:
--- cut ---
{{=selected_rows[0].servername()}}

But I got:

  File "gluon/sql.py", line 665, in __getattr__
    return dict.__getitem__(self,key)
KeyError: 'servername'

If I only change:

class web_sites_extra():
        def servername( self ):
                def lzy(  ):
                        x = 'sfjha'
                        return x
        return lzy

to:

class web_sites_extra():
        def lzy( self ):
                        x = 'sfjha'
                        return x
        def servername( self ):
                return self.lzy

it works.

Reply via email to