问题
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