>
> db.define_table('Account_Master',Field('Account',requires=IS_NOT_EMPTY()),Field('Sewadari1'),Field('Mb1'),Field('Sewadari2'),Field('Mb2'),Field('City'),Field('District'),Field('State'),Field('Email'),Field('Remark'),format='%(Account)s
>  
> %(State)s ')
>
> db.define_table('Transaction_Master',Field('Account',db.Account_Master,requires=IS_IN_DB(db,'Account_Master.id',
>  
> '%(Account)s %(State)s',zero=T('choose 
> one'))),Field('Exam_Date','date'),Field('Entry_Date','date',default=request.now),Field('Form_1','upload'),Field('Form_1_Name'),Field('Schoolwise_Form','upload'),Field('Schoolwise_Form_Name'),format='%(Account)s
>  
> %(Exam_Date)s')
>
> When i try to represent the account field of Transaction_Master table in 
> sqlform.factory as:
>  form=SQLFORM.factory(Field('TID',requires=IS_IN_DB(db,
> db.Transaction_Master.id,'%(Account)s %(Exam_Date)s %(id)s')))
>
> I am getting the id field of account in the sqlform.factory form. Is there 
> a way so that i may get the account name which that id field refers to in 
> the account master?
>

Your IS_IN_DB validator refers to '%(Account)s', but the Account field in 
the Transaction_Master table is a reference field and therefore just stores 
integers (i.e., record ID's), so that's what you're getting -- the format 
does not propagate from the db.Account_Master table to the 
db.Transaction_Master table. Instead, though, the format argument to 
IS_IN_DB can be a callable (e.g., a lambda) that takes a record and returns 
the representation you want. So, try:

IS_IN_DB(db, db.Transaction_Master.id,
    lambda r: '%s %s %s' % (db.Account_Master[r.Account].Account, r.
Exam_Date, r.id))

Note, the format argument to define_table() can also be a callable.

Anthony

Reply via email to