>
> db.define_table('account_type',
> Field('type')
> )
>
> auth = Auth(db)
> auth.settings.extra_fields['auth_user'] = [
> Field('account_type', db.account_type)]
> auth.define_tables(username=True)
>
>
> db.auth_user.requires = IS_IN_DB(db, 'account_type.type')
>
First, it would be db.auth_user.account_type.requires (the "requires"
attribute belongs to the field, not the table).
Second, it is a reference field so must take an integer (specifically, it
should be integer id's from the account_type.id field, not string values
from the account_type.type field). You want IS_IN_DB(db, 'account_type.id').
However, in the drop-down, that will show integer id's instead of "type"
values. To get the dropdown to display "type" values (but still submit
integer id's behind the scenes), do IS_IN_DB(db, 'account_type.id',
'%(type)s'). Actually, there's an easier way to achieve all that --
instead, just add the following to your account_type table definition:
db.define_table('account_type',
Field('type'),
format='%(type)s')
Now all you have to do is:
auth.settings.extra_fields['auth_user'] = [Field('account_type', db.
account_type)]
and you'll automatically get the IS_IN_DB validator with the "type" values
showing in the dropdown.
Anthony
--