rendering foreign keys as a pulldown in web2py appadmin

六眼飞鱼酱① 提交于 2019-12-12 03:42:22

问题


part of my web2py database schema looks like so:

db.define_table('asset',
    Field('name', unique=True, requires=IS_NOT_EMPTY()),
    Field('description', 'text')
)

db.define_table('wallet',
    Field('name', unique=True, requires=IS_NOT_EMPTY()),
    Field('description', type='text')
)

db.define_table('wallet_asset',
    Field('wallet_id', 'reference wallet'),
    Field('asset_id', 'reference asset')
)

When I visit appadmin to enter a new wallet_asset record, I would like for the wallet_id and asset_id fields to be pulldowns that render the names of those referenced tables.

How do I do this?


回答1:


Use format record representation at the time of defining tables.

Read format: Record representation

Your schema will look like this:

db.define_table('asset',
    Field('name', unique=True, requires=IS_NOT_EMPTY()),
    Field('description', 'text'),
    format='%(name)s'
)

db.define_table('wallet',
    Field('name', unique=True, requires=IS_NOT_EMPTY()),
    Field('description', type='text'),
    format='%(name)s'
)


来源:https://stackoverflow.com/questions/40252123/rendering-foreign-keys-as-a-pulldown-in-web2py-appadmin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!