扩展现有的web2py数据库
我有一个已经存在的web2py应用程序。现在我需要创建一个新的注册表单,这个表单要用到一个数据库表,其中有一个字段需要从另一个表中选择一行数据。
这个功能和你在注册表单中常见的国家字段类似,不过我希望用户能够在国家表中添加新的国家,如果这个国家还不存在的话。
2 个回答
1
你可以使用一种一对多的关系(参考这本书):
db.define_table('country',
Field('name'),
Field('desc'))
db.define_table('user',
Field('name'),
Field('origin'), db.country))
顺便提一下,你可以在web2py的Google小组上提问,Massimo可能会更快回复你。
4
对之前的回答做个小改进:
# create auth
auth = Auth(db)
# create the country table
db.define_table('country',
Field('name'),
Field('desc'),
format = '%(name)s')
# say you want to add it to auth_user table (not yet created)
auth.settings.extra_fields['auth_user']=[Field('country','reference country')]
# ask auth to make the auth tables, including auth_user
auth.define_tables()
JMax说得对。我们在web2py的邮件列表上反应更快。