2011-08-12 110 views
2

我有一個現有的web2py應用程序。現在我需要使用db表創建一個新的註冊表單,其中包含需要來自不同表格的行的字段。擴展現有的web2py數據庫

這應該與您通常在註冊表單中看到的國家/地區字段類似,但我希望人們能夠在「國家/地區」表中添加值(如果該值尚不存在)。

回答

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郵件列表上反應更快。

+0

感謝Massimo,我感謝你的改進:)我也會檢查一下Google Group,謝謝。 – Jarrod

+0

剛剛嘗試這樣做,但我得到的錯誤:int()與基數10無效字面值:'水管工'。 這是我的代碼: 'db.define_table(auth.settings.table_user_name, 字段( '標題',db.title) 格式= '%(名)S', ) db.define_table( 'title', Field('name'), format ='%(name)s' )' 對我在做什麼錯誤感到困惑。 – Jarrod

1

您可以使用一個一對多的關係(參見book):

db.define_table('country', 
       Field('name'), 
       Field('desc')) 

db.define_table('user', 
       Field('name'), 
       Field('origin'), db.country)) 

順便說一句,你可以問在哪裏web2py Googlegroup馬西莫可能會比較活潑

+0

謝謝!我不知道它被稱爲一對多的關係:) – Jarrod