Am 16.06.2012 22:30, schrieb Anthony:
> Reference fields automatically get an IS_IN_DB validator, but you can
> explicitly specify your own and pass a DAL Set as the first argument
> to filter the auth_user records:
>
> ||
> db.define_table('t_customer_contact',
>     Field('f_customer',db.t_customer,label=T("customer")),
>     Field('f_contact',db.auth_user,label=T("contact"),
>        
> requires=IS_IN_DB(db(query),'auth_user.id',format=db.auth_user._format)),
>     [etc.]
>
> The db(query) part of that should specify a query to restrict the set
> to users with particular memberships. See the book section on database
> validators
> <http://web2py.com/books/default/chapter/29/7#Database-validators> for
> more details.
>
> Anthony
Hello Anthony,

thanks, this works like a charm.

    query = ((db.auth_user.id == db.auth_membership.user_id)&
             (db.auth_membership.group_id ==
    auth.id_group(settings.groupname_customer)))

    db.define_table('t_customer_contact',
                    Field('f_customer', db.t_customer, label=T("customer")),
                    Field('f_contact', db.auth_user, label=T("contact"),
                          requires=IS_IN_DB(db(query), db.auth_user.id,
    '%(first_name)s %(last_name)s (%(email)s)')
                          ),
                    auth.signature,
                    format='%(f_contact)s',
                    migrate=settings.migrate)

But now when I have an SQLFORM.grid like this:

    query   = ((db.t_customer_contact.f_customer == customer_id))

    contact_list = SQLFORM.grid(query=query,
                                        
    fields=[db.t_customer_contact.f_contact],
                                         editable=False,
                                        
    deletable=True,                               
                                         details=False,
                                         csv=False,
                                         searchable=True,
                                         create=False,
                                         )

   
I will not see the f_contact as a name anymore but only as the ids.
When I remove the requires from the table definition the ids are
resolved to the names again.

Kind regards
Cornelius

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to