If I understand the problem is that you first_name fields does not show a
dropdown of users.
This line is incorrect:
*Field('first_name', 'reference auth_user', label='User', writable=True,
readable=True, notnull=True, required=True, ondelete='NO ACTION',
requires=IS_IN_DB(db, db.auth_user, '%(id)s %(first_name)s
%(last_name)s')),*
Should be
Field('first_name', 'reference auth_user', label='User', writable=True,
readable=True, notnull=True, required=True, ondelete='NO ACTION',
requires=IS_IN_DB(db, db.auth_user, '%(id)s %(first_name)s %(last_name)s')),
*Or better*
Field('first_name', 'reference auth_user', label='User', writable=True,
readable=True, notnull=True, required=True, ondelete='NO ACTION'),
*and before the table definition set once for all*
*db.auth_user._format = *'%(id)s %(first_name)s %(last_name)s'
Try avoid IS_IN_DB(...), it is automatic for reference fields.
On Friday, 13 December 2013 14:48:14 UTC-6, Michel Hayek wrote:
>
> Hi guys,
>
> I have 2 tables defined Auth_User(PK=id) and Companies(PK=ID)
> I also defined User_Has_Companies which has 2 columns USER_ID and COMP_ID
> together should form a PK.
>
> *db.py:*
>
>
>
> *#################################db.define_table('t_companies',
> Field('f_coname',label='Company Name', required=True,ondelete='NO
> ACTION',notnull=True), Field('f_comanager',label='Company
> Manager', required=False,ondelete='NO ACTION',notnull=False),
> Field('f_coemail',label='Company Email', required=False,ondelete='NO
> ACTION',notnull=False) )db.t_companies.f_coemail.requires =
> IS_EMAIL(error_message='invalid
> email!')####################################*
> *db.define_table('t_user_has_companies',*
> * Field('first_name', 'reference auth_user', label='User',
> writable=True, readable=True, notnull=True, required=True, ondelete='NO
> ACTION', requires=IS_IN_DB(db, db.auth_user, '%(id)s %(first_name)s
> %(last_name)s')),*
> * Field('f_coname', 'reference t_companies',
> label='Company', writable=True, readable=True, notnull=True, required=True,
> ondelete='NO ACTION', requires=IS_IN_DB(db, db.t_companies, '%(id)s
> %(f_coname)s'))*
> * )*
>
> *db.t_user_has_companies.first_name.requires=IS_NOT_IN_DB(db(db.t_user_has_companies.f_coname==request.vars.f_coname),db.t_user_has_companies.first_name)*
>
> *In default.py:*
> *@auth.requires_login()*
> *def usercompanies():*
> * grid=SQLFORM.grid(db.t_user_has_companies)*
> * return locals()*
>
> it works fine but the problem is i only get one drop down for the
> companies, as for the User it appears a text box. How this one also be set
> to drop down box?
>
> Thanks
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.