Seems like the code and the problem are changing with every post here. 
Note, if your represent function includes a field that itself has a 
represent attribute, the represent attribute of the included field does not 
get applied -- you have to be explicit about it. So, instead of your code, 
you should do:

Field('supptile',represent=lambda id, r: '%s%s'% (r.suppliercode.
suppliercode, r.tilename))

r.suppliercode.suppliercode is a recursive select, retrieving the 
suppliercode value from the db.supplier record referenced by 
r.suppliercode. Note, db.product.suppliercode is a confusing name for that 
field because it actually references the db.supplier table (which has a 
suppliercode field) -- you might consider just calling it 
db.product.supplier (or maybe db.product.supplier_id).

Anthony

On Wednesday, July 10, 2013 9:23:30 AM UTC-4, greenpoise wrote:
>
> because suppliercode and tilename are the two values I want to 
> concatenate. I even tried adding a represent to the series table (since the 
> series table is directly related to the supplier table) and called the 
> represent field from the product table, in that case it brings the 
> suppliercode.id instead of the value itself.  Here:
>
> db.define_table('cut',
>     Field('name'))
>
>
> db.define_table('finish',
>     Field('name'),
>     Field('abbr'))
> db.finish.name.requires = IS_NOT_IN_DB(db,db.finish.name)
> db.finish.abbr.requires = IS_NOT_IN_DB(db,db.finish.abbr)
>
> db.define_table('supplier',
>     Field('suppliercode'),
>     Field('suppliername'),
>     format='%(suppliercode)s')
> db.supplier.suppliercode.requires = 
> IS_NOT_IN_DB(db,db.supplier.suppliercode)
> db.supplier.suppliername.requires = 
> IS_NOT_IN_DB(db,db.supplier.suppliername)
>
>
>  
> db.define_table('colorgroup',
>     Field('groupname'),
>     Field('description'))
>
>
> db.define_table('material',
>     Field('name'),
>     Field('abbr'))
> db.material.name.requires = IS_NOT_IN_DB(db,db.material.name)
> db.material.abbr.requires = IS_NOT_IN_DB(db,db.material.abbr)
>
> db.define_table('color',
>     Field('number'),
>     Field('name'),
>     Field('colorgroup','reference colorgroup'))
> db.color.number.requires = IS_NOT_IN_DB(db,db.color.number)
> db.color.colorgroup.requires = IS_IN_DB(db,db.colorgroup.id
> ,'%(groupname)s')
>
> db.define_table('tileuse',
>     Field('name'),
>     Field('abbreviation'))
>         
> db.define_table('conversiontype',
>     Field('type'),
>     Field('conversionname'))
> db.conversiontype.type.requires = IS_NOT_IN_DB(db,db.conversiontype.type)
> db.conversiontype.conversionname.requires = 
> IS_NOT_IN_DB(db,db.conversiontype.conversionname)
>
>     
> ##########################
> ##END OF HELPER TABLES
> #######################
>
> db.define_table('series',
>     Field('supplier','reference supplier'),
>     Field('seriesname'),
>     Field('seriesdescription'),
>     Field('description'),
>     Field('colorgroup','reference colorgroup'),
>     Field('material', 'reference material'),
>     Field('tileuse','reference tileuse'),
>     Field('size1','float'),
>     Field('size2','float'),
>     Field('price'),
>     Field('cost'),
>     
> Field('created_by',db.auth_user,default=me,writable=False,readable=False),
>     
> Field('created_on','datetime',default=request.now,writable=False,readable=False))
> db.series.material.requires = IS_EMPTY_OR(IS_IN_DB(db,db.material.id
> ,'%(name)s'))
> db.series.seriesname.requires = IS_NOT_IN_DB(db,db.series.seriesname)
> #db.series.seriesnumber.compute=lambda r: '%s%s'% 
> (r['suppliercode'],r['seriesname'][0:3])
> db.series.supplier.requires = IS_IN_DB(db,db.supplier.id
> ,'%(suppliername)s')
> db.series.colorgroup.requires = IS_IN_DB(db,db.colorgroup.id
> ,'%(groupname)s')
> db.series.tileuse.requires = IS_EMPTY_OR(IS_IN_DB(db,db.tileuse.id
> ,'%(name)s'))
> db.series.size1.requires=IS_EMPTY_OR(IS_IN_SET(SIZES))
> db.series.size2.requires=IS_EMPTY_OR(IS_IN_SET(SIZES))
> db.series._singular = "Series"
> db.series._plural = "+Series"
>
>        
>                       
> db.define_table('product',
>     Field('series', 'reference series'),
>     Field('finish', 'reference finish'),
>     Field('cut', 'reference cut'),
>     Field('suppliercode', 'reference supplier',requires=IS_IN_DB(db,
> db.supplier.id,'%(suppliercode)s')),
>     Field('supptile',represent=lambda id, r: '%s%s'% 
> (r.suppliercode,r.tilename)),
>     Field('tilename'),
>     Field('description'),
>     Field('size1','float'),
>     Field('size2','float'),
>     Field('color','reference color'),
>     Field('price'),
>     Field('cost'),
>     Field('picture', 'upload'),
>     Field('conversiontype'),
>     Field('inactive','boolean'),
>     Field('sortable','integer'),
>     
> Field('added_by',db.auth_user,default=me,writable=False,readable=False),
>     
> Field('created_on','datetime',default=request.now,writable=False,readable=False))
> db.product.series.requires = IS_EMPTY_OR(IS_IN_DB(db,db.series.id
> ,'%(seriesname)s'))
> db.product.color.requires = IS_EMPTY_OR(IS_IN_DB(db,db.color.id
> ,'%(name)s'))
> db.product.conversiontype.requires = IS_EMPTY_OR(IS_IN_DB(db,
> db.conversiontype.id,'%(conversionname)s'))
> db.product.finish.requires = IS_EMPTY_OR(IS_IN_DB(db,db.finish.id
> ,'%(name)s'))
> db.product.cut.requires = IS_EMPTY_OR(IS_IN_DB(db,db.cut.id,'%(name)s'))
> db.product.tilename.requires = IS_NOT_IN_DB(db,db.product.tilename)
> db.product.size1.requires=IS_EMPTY_OR(IS_IN_SET(SIZES))
> db.product.size2.requires=IS_EMPTY_OR(IS_IN_SET(SIZES))
>
>
>
> Thanks!
>
>
> On Wednesday, July 10, 2013 6:17:11 AM UTC-7, Anthony wrote:
>>
>> Not sure I understand -- the error was with the "supplier" attribute -- 
>> what does it have to do with tilename? It would help if you could post the 
>> exact model code and explain exactly what is going wrong where. If you get 
>> errors when values are None, then just include a condition that checks for 
>> None (e.g., r.supplier.suppliercode if r.supplier else '').
>>
>> Anthony
>> On Wednesday, July 10, 2013 9:10:36 AM UTC-4, greenpoise wrote:
>>>
>>> if I add it, DB Administration works but I its value is NONE(tilename). 
>>> Is as if I can do this representation on a top-bottom approach but not the 
>>> other way around.
>>>
>>>
>>>
>>>
>>> On Wednesday, July 10, 2013 6:04:08 AM UTC-7, Anthony wrote:
>>>>
>>>> Well, I don't see a "supplier" field in the db.product model.
>>>>
>>>> On Wednesday, July 10, 2013 8:52:04 AM UTC-4, greenpoise wrote:
>>>>>
>>>>> sorry. This is the error I get:
>>>>>
>>>>> File "/home/xyz/Applications/web2py/gluon/sqlhtml.py", line 3122, in 
>>>>> __init__
>>>>>     r = represent(field, r, record)
>>>>>   File "/home/xyz/Applications/web2py/gluon/sqlhtml.py", line 66, in 
>>>>> represent
>>>>>     return f(value, record)
>>>>>   File 
>>>>> "/home/xyz/Applications/web2py/applications/MOS/models/db_catalog.py" 
>>>>> <http://127.0.0.1:8000/admin/default/edit/MOSAIC_POSx2/models/db_catalog.py>,
>>>>>  line 102, in <lambda>
>>>>>     Field('supptile',represent=lambda id, r: '%s%s'% 
>>>>> (r.supplier.suppliercode,r.product.tilename)),
>>>>> AttributeError: 'Row' object has no attribute 'supplier'
>>>>>
>>>>>
>>>>> On Wednesday, July 10, 2013 5:13:55 AM UTC-7, Anthony wrote:
>>>>>>
>>>>>> Hard to help without knowing what the error is.
>>>>>>
>>>>>> On Wednesday, July 10, 2013 1:35:01 AM UTC-4, greenpoise wrote:
>>>>>>>
>>>>>>> AGh..tilename was in it, I just didnt include it in this thread:
>>>>>>>
>>>>>>>
>>>>>>> db.define_table('supplier',
>>>>>>>    Field('suppliercode'),
>>>>>>>    Field('suppliername'),
>>>>>>>    format='%(suppliercode)s')
>>>>>>> db.supplier.suppliercode.requires = IS_NOT_IN_DB(db,db.supplier.
>>>>>>> suppliercode)
>>>>>>> db.supplier.suppliername.requires = IS_NOT_IN_DB(db,db.supplier.
>>>>>>> suppliername)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> db.define_table('series',
>>>>>>>    Field('supplier','reference supplier'),
>>>>>>>   Field('seriesname'),
>>>>>>>    Field('seriesdescription'),
>>>>>>>    Field('description'))
>>>>>>>
>>>>>>>
>>>>>>> db.define_table('product',
>>>>>>>    Field('series', 'reference series'),
>>>>>>>    Field('supptile',represent=lambda id, r: '%s%s'% (r.supplier.
>>>>>>> suppliercode,r.tilename)),
>>>>>>>    Field('tilename'),
>>>>>>>    Field('description'),
>>>>>>>    Field('conversiontype'),
>>>>>>>    Field('inactive','boolean'))
>>>>>>>
>>>>>>>
>>>>>>> controller function:
>>>>>>>
>>>>>>> grid = SQLFORM 
>>>>>>> <http://127.0.0.1:8000/examples/global/vars/SQLFORM>.grid(db.series,left
>>>>>>>  
>>>>>>> =[db.series.on(db.series.id==db.product.series),db.supplier.on(db.supplier.id==db.series.supplier)],fields=[db.supplier.suppliercode,db.product.supptile,db.product.tilename],
>>>>>>>  headers = {'supplier.suppliercode': 
>>>>>>> 'SUPPLIERCODE','series.supptile':'ITEMCODE','product.tilename':'REORDER#'})
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> As it is, the grid works as I want. I get the supptile which is a 
>>>>>>> concatenation of the suppliercode and tilename. When I go to database 
>>>>>>> administration, which I use, the product table prompts me an error. 
>>>>>>> Agh!!! 
>>>>>>>  Thanks so much Anthony!
>>>>>>>
>>>>>>> **I hope I didnt miss anything**
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Tuesday, July 9, 2013 10:02:00 PM UTC-7, Anthony wrote:
>>>>>>>>
>>>>>>>> Can you show your new code? So far, all we see is 
>>>>>>>> r.product.tilename, which won't work because r.product is a LazySet 
>>>>>>>> object 
>>>>>>>> -- you have to do r.product.select().first().tilename, or something 
>>>>>>>> along 
>>>>>>>> those lines (though that will just give you the tilename of the first 
>>>>>>>> product that references the record). Also, in the models you have 
>>>>>>>> shown, 
>>>>>>>> there is no tilename field in the db.product table.
>>>>>>>>
>>>>>>>> Anthony
>>>>>>>>
>>>>>>>> On Tuesday, July 9, 2013 11:34:27 PM UTC-4, greenpoise wrote:
>>>>>>>>>
>>>>>>>>> I re-opened this as I keep getting the same error. 
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Tuesday, July 9, 2013 4:12:49 PM UTC-7, greenpoise wrote:
>>>>>>>>>>
>>>>>>>>>> I think I got it by reading the recursive select section. 
>>>>>>>>>> THanks!!!
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Tuesday, July 9, 2013 3:55:04 PM UTC-7, Anthony wrote:
>>>>>>>>>>>
>>>>>>>>>>> Would help if you showed your data models. Presumably the 
>>>>>>>>>>> db.product table includes a reference field that references this 
>>>>>>>>>>> table. 
>>>>>>>>>>> That allows you to do a recursive select in reverse (see the last 
>>>>>>>>>>> part of this 
>>>>>>>>>>> section<http://web2py.com/books/default/chapter/29/06#Recursive-selects>).
>>>>>>>>>>>  
>>>>>>>>>>> When you select a record from this table (let's call the record 
>>>>>>>>>>> "r"), then 
>>>>>>>>>>> r.product is a LazySet object that refers to all the records in 
>>>>>>>>>>> db.product 
>>>>>>>>>>> that have a reference to this particular record. You can then use 
>>>>>>>>>>> that as 
>>>>>>>>>>> any DAL Set object. If you need to further filter the set, you can 
>>>>>>>>>>> add a 
>>>>>>>>>>> condition by doing r.product(some_query), and if you want to select 
>>>>>>>>>>> the 
>>>>>>>>>>> records, you can do r.product.select(). Assuming there are 
>>>>>>>>>>> potentially 
>>>>>>>>>>> multiple product records that reference a given record in this 
>>>>>>>>>>> table, it's 
>>>>>>>>>>> not clear how you would want to use those records to construct the 
>>>>>>>>>>> "represent" output for the field.
>>>>>>>>>>>
>>>>>>>>>>> Anthony
>>>>>>>>>>>
>>>>>>>>>>> On Tuesday, July 9, 2013 6:32:33 PM UTC-4, greenpoise wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> I am getting this error. My grid works fine but when I try to 
>>>>>>>>>>>> log into the database administration tool, I get this error. Any 
>>>>>>>>>>>> clue?
>>>>>>>>>>>>
>>>>>>>>>>>> File 
>>>>>>>>>>>> "/home/xxx/Applications/web2py/applications/APPLICACION/models/db_catalog.py"
>>>>>>>>>>>>  
>>>>>>>>>>>> <http://127.0.0.1:8000/admin/default/edit/MOSAIC_POSx2/models/db_catalog.py>,
>>>>>>>>>>>>  line 72, in <lambda>
>>>>>>>>>>>>     Field('supptile',represent=lambda id, r: '%s%s'% 
>>>>>>>>>>>> (r.supplier.suppliercode,r.product.tilename)),
>>>>>>>>>>>> AttributeError: 'LazySet' object has no attribute 'tilename'
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>

-- 

--- 
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.


Reply via email to