Posts

Customizing web2py auth_user Table

The following lines of code take place in the db.py file.

Declaring an auth_user table

# Set up a default auth user table

auth.define_tables(username=False, signature=False)

Declaring a customized auth_user table

# Set up a customized auth_user table

auth.settings.extra_fields[‘auth_user’]=[Field(‘registration_complete’), Field(‘favorite_number’)]

auth.define_tables(username=False, signature=False)

 

Call the function

auth.settings.extra_fields[‘auth_user’]=[Field(‘registration_complete’), Field(‘favorite_number’)]

Specify the table you want to alter

auth.settings.extra_fields[‘auth_user’]=[Field(‘registration_complete’), Field(‘favorite_number’)]

Specify the Fields you would like to add to the table 

auth.settings.extra_fields[‘auth_user’]=[Field(‘registration_complete’), Field(‘favorite_number’)]

Important!

When you are creating a customized auth_user table you must place the auth.settings.extra_fields statement before the auth.define_tables statement. If you don’t put it before the auth.define_tables statement, the auth_user table will not be customized and will be default.