Jarrod
Jarrod

Reputation: 1705

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 'Country' Table if the value doesn't already exist.

Upvotes: 2

Views: 871

Answers (2)

Massimo
Massimo

Reputation: 1653

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.

Upvotes: 4

JMax
JMax

Reputation: 26601

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

Upvotes: 1

Related Questions