IMHO you can't have a format definition that needs values from different 
tables to be represented.... you need a separate function to do that.

On Saturday, December 27, 2014 12:14:50 AM UTC+1, [email protected] wrote:
>
> My application manages debits of hardware to personnel
>
> Here is my model:
>
> ## table that holds firms providing hardware
> db.define_table('providers',
>                 Field('eponymia', 'string', label='Name'),
>                 Field('address', 'string', label='Address'),
>                 Field('perioxi', 'string', label='Area'),
>                 Field('zip', 'string', label='ZIP'),
>                 Field('phone', 'string', label='Telephone'),
>                 Field('created_on', 'datetime',
>                       default=request.now,
>                       update=request.now,
>                       writable=False,
>                       readable=False),
>                 Field('created_by',
>                       'reference auth_user',
>                       default=auth.user_id,
>                       update=auth.user_id,
>                       writable=False,
>                       readable=False),
>                 format='%(eponymia)s'
>                 )
>
> ## table that holds types of hardware, i.e. PC, monitor, rack, Flash etc.
> db.define_table('type_of_hardware',
>                 Field('hwType', 'string', length=100, label='Hardware 
> Type'),
>                 format='%(hwType)s'
>                 )
>
> ## table that holds personnel names
> db.define_table('personnel',
>                 Field('pers_code', type='id', label='Employee Code'),
>                 Field('pers_surname', 'string', label='Surname'),
>                 Field('klados', 'string', label='Code of Sector'),
>                 Field('un_code', 'integer', label='Code of Branch'),
>                 Field('date_occupation', 'date', label='Date Hired'),
>                 Field('ergsxesi', 'string', label='Kind of Job'),
>                 Field('pers_indpause', 'integer', label='Active?'),
>                 Field('apox', 'date', label='Date Retired'),
>                 format='%(pers_surname)s, %(pers_code)s'
>                 )
>
> ## table that holds the hardware
> db.define_table('hardware',
>                 Field('typeOfItem', 'reference type_of_hardware', 
> label='Type'),
>                 Field('provider', 'reference providers', label='Provider'),
>                 Field('manufacturer', 'string', length=15, 
> label='Manufacturer'),
>                 Field('productSeries', 'string', length=30, 
> label='Series', default=""),
>                 Field('model', 'string', length=30, label='Model', 
> default=""),
>                 Field('serialNo', 'string', length=50, label='Serial 
> Number', default=""),
>                 Field('partNo', 'string', length=50, label='Part Number', 
> default=""),
>                 Field('notes', 'text', label='Notes'),
>                 Field('dt_buy', 'date', label='Date Bought', 
> requires=IS_EMPTY_OR(IS_DATE("%d-%m-%Y"))),
>                 Field('cost', 'decimal(12, 2)', label='Costed'),
>                 Field('FPA', 'decimal(4, 2)', label='VAT', default=0.23),
>                 Field('available', 'boolean', label='Available?', 
> default=True),
>                 Field('destroyed', 'date', label='Date Destroyed', 
> requires=IS_EMPTY_OR(IS_DATE("%d-%m-%Y"))),
>                 Field('ODDY', 'date', label='Date ODDY', 
> requires=IS_EMPTY_OR(IS_DATE("%d-%m-%Y"))),
>                 Field('registerPage', 'integer', label='Registration 
> Page'),
>                 Field('created_on',
>                       'datetime',
>                       default=request.now,
>                       update=request.now,
>                       writable=False,
>                       readable=False),
>                 Field('created_by',
>                       'reference auth_user',
>                       default=auth.user_id,
>                       update=auth.user_id,
>                       writable=False,
>                       readable=False),
>                 format='%(typeOfItem.hwType)s, %(manufacturer)s, 
> %(productSeries)s, %(model)s, %(serialNo)s'
>                 )
> db.hardware.id.readable = False
> db.hardware.available.writable = db.hardware.available.readable = False
>
> ## table that holds debits of hardware to personnel (many-to-many)
> db.define_table('debit',
>                 Field('id_personnel', 'reference personnel', 
> label='Employee'),
>                 Field('id_hardware', 'reference hardware', 
> label='Hardware'),
>                 Field('dtstrt_of_debit', 'date', label='Start Debit', 
> requires=IS_DATE("%d-%m-%Y")),
>                 Field('dtend_of_debit', 'date', label='End Debit', 
> requires=IS_EMPTY_OR(IS_DATE("%d-%m-%Y"))),
>                 Field('notes', 'text', label='Notes'),
>                 Field('created_on',
>                       'datetime',
>                       default=request.now,
>                       update=request.now,
>                       writable=False,
>                       readable=False),
>                 Field('created_by',
>                       'reference auth_user',
>                       default=auth.user_id,
>                       update=auth.user_id,
>                       writable=False,
>                       readable=False),
>                 plural='Debits',
>                 singular='Debit'
>                 )
>
> Now in my controller I have:
> def test():
>     formUpdateDebit = SQLFORM(db.debit,
>                                             record=db.debit[8],
>                                             fields=['id_personnel',
>                                                       'id_hardware',
>                                                       'dtstrt_of_debit',
>                                                       'dtend_of_debit',
>                                                       'notes'
>                                                      ]
>                                             )
>     return dict(formUpdateDebit=formUpdateDebit)
>
> But this throws the error: <type 'exceptions.AttributeError'> 'Table' 
> object has no attribute 'typeOfItem.hwType'
>
>
> I think this has to do with the 
>
> format='%(typeOfItem.hwType)s, %(manufacturer)s, %(productSeries)s, 
> %(model)s, %(serialNo)s'
>
> line in the definition of the hardware table above, but I am not sure.
>
> I want my forms to show the corresponding type of hardware (not the id). 
> Is this format wrong?
>
> Thanks in advance!
>
> Tom
>

-- 
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/d/optout.

Reply via email to