Note that there are some explanatory texts on larger screens.

plurals
  1. POweb2py Custom User Profile?
    primarykey
    data
    text
    <blockquote> <p>What is the 'correct' way to extend the base <code>auth_user</code> table/the whole <code>auth</code> system in order to support a number of custom user profile fields (such as username, location, birthday, etc.)?</p> </blockquote> <p>I've caught glances of approaches from Googling, but no one ever seems to give a straight answer. The answer seems to be either completely replacing the base <code>auth_user</code> table with a custom one (and letting the auth system know), or creating a new extension table with a foreign key reference back to the base <code>auth_user</code> table. The first seems to have reusability problems, the second is going to have problems with forms and such.</p> <p>Does anyone have any pointers to patch in something as universal as custom user profiles without breaking too much?</p> <p><strong>EDIT:</strong> A bit more reading suggests overriding the base <code>auth_user</code> table is the way to go, and after some trial and error, I've found it's as easy as dropping in a block of code:</p> <pre><code># before define_tables() auth.settings.table_user = db.define_table('auth_user', Field('email', length=128,label=T('Email'), default='', unique=True), Field('user_name', length=128, label=T('User name'), default='', unique=True, requires=IS_NOT_IN_DB(db, 'auth_user.user_name') ), Field('password', 'password', readable=False, label=T('Password'), requires=CRYPT() ), Field('first_name', length=128, label=T('First name'), default='', requires=(IS_NOT_EMPTY(error_message=auth.messages.is_empty), IS_NOT_IN_DB(db, 'auth_user.first_name')) ), Field('last_name', length=128, label=T('Last name'), default='', requires=(IS_NOT_EMPTY(error_message=auth.messages.is_empty), IS_NOT_IN_DB(db, 'auth_user.last_name')) ), Field('registration_key', length=128, default='', writable=False, readable=False), Field('country', 'string', length=15, label=T('Country'), requires=IS_NULL_OR(IS_IN_SET(('England'))) ), ) </code></pre> <p>So long as this gets executed after <code>auth = Auth(db)</code> and before <code>auth.define_tables()</code> in models/db.py, it all seems to work out okay. The fields show up on the user profile page, and everything else still works as expected.</p> <p>Not sure how to answer my own question, so in the meantime, if someone could explain <em>why</em> this is the right way to do it, and what else must be kept in mind, I'd appreciate it!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload