Are you talking about the items in the select/options drop-down on forms?
If so, that is controlled by the "label" argument (i.e., third argument) to
the IS_IN_DB validator specified for the field. If you don't specify any
validators for a given reference field and the referenced table includes a
_format attribute, then the field automatically gets an IS_IN_DB validator
with the label set to the _format attribute of the referenced table.
Alternatively, you can specify your own IS_IN_DB validator with a "label"
argument. The "label" argument (and the _format attribute) can be a lambda
that takes a row of the referenced table.
See http://web2py.com/books/default/chapter/29/6#Record-representation.
Anthony
On Wednesday, April 4, 2012 1:58:18 AM UTC-4, Annet wrote:
>
> Hi Anthony,
>
> In db.py I defined these tables:
>
> db.define_table('Organization',
>
> Field('nodeID',db.Node,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False),
> Field('name',length=128,default='',notnull=True),
> ...,
> migrate=False)
>
>
> db.define_table('Address',
>
> Field('nodeID',db.Node,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False),
> ...,
> migrate=False)
>
> db.Address.nodeID.requires=[IS_IN_DB(db,'Node.id','%(id)s',zero='select a
> value'),IS_NOT_IN_DB(db(db.Address.addrType==request.vars.addrType),db.Address.nodeID,error_message='combination
>
> node and addr type already in database')]
> db.Address.nodeID.represent=lambda nodeID, row:
> db(db.Organization.nodeID==nodeID).select().first().name
>
>
> In case of this URL:
> http://127.0.0.1:8000/init/appadmin/select/db?query=db.Address.id%3E0
> Address.nodeID is represented by Organization.name.
>
> In case of this URL:
> http://127.0.0.1:8000/init/appadmin/update/db/Address/1
> Address.nodeID is 1.
>
>
> I also have custom registration process, in the function in which I add
> the user I have the following lines of code:
>
> @auth.requires(lambda: auth.has_membership(ADMIN))
> def adduser():
> ....
> row=db(db.Register.id
> ==request.args(0)).select(db.Register.ALL).first()
>
> organization=db(db.Organization.cocNumber==row.cocNumber).select(db.Organization.ALL).first()
> id=organization.nodeID
> db.auth_user.nodeID.represent=lambda nodeID,row: organization.name
> form=SQLFORM.factory(db.auth_user,ignore_rw=True,separator='')
> ...
> form.vars.nodeID=id
> if form.process().accepted:
> ...
> elif form.errors:
> ...
> else:
> ...
> return dict(form=form)
>
> and in the view {{=form}}
>
> In this case I experience the same problem nodeID is 1 instead of
> Organization.name
>
>
> I hope I provided sufficient information.
>
> Kind regards,
>
> Annet
>