Extending an existing web2py database
I have an existing web2py application. Now I need to create a new registration form using a db Table that includes a Field that requires a Row from a different Table.
This should be similar to what you commonly see with Country Fields in registration forms, except I want people to be able to add values to the 开发者_Go百科'Country' Table if the value doesn't already exist.
Making a small improvement to the previous response:
# 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 is right. We are more responsive on the web2py mailing list.
You can use a one to many relation (cf. the book):
db.define_table('country',
Field('name'),
Field('desc'))
db.define_table('user',
Field('name'),
Field('origin'), db.country))
Btw, you can ask your questions on the web2py Googlegroup where Massimo will probably be more reactive
精彩评论