Hi,
This is wrecking my head. If anybody can advise please.
I have two tables (simplified version)
db.define_table("listing_item",
Field('title',length=32),
Field('short_description',length=512)
db.define_table("price", ###there are number of weekly records for one
listing_item record
Field('listing',db.listing_item),
Field("name", "string", length=64),
Field("weekly","decimal(13,2)"),
#####Controller#####
def index():
item = db(db.listing_item.id>0).select()
return dict(item=item)
####View####
{{for item in item:}}
<div> Listing {{item.title}} and max price:
{{prices=db((db.price.id>0) &
(db.price.listing==item)).select(db.price.weekly,distinct=True)}}
{{priceMax= prices.last()}}
{{=priceMax}}
</div>
{{pass}}
####Result###
Listing Test1 and max price is <Row {'weekly': Decimal('100.00')}>
Listing Test2 and max price is <Row {'weekly': Decimal('100.00')}>
....
What I'm trying to achieve is as follows:
Listing Test1 and max price is 100.00
Listing Test2 and max price is 100.00
...
if I try:
{{for item in item:}}
<div> Listing {{item.title}} and max prices:
{{prices=db((db.price.id>0) &
(db.price.listing==item)).select(db.price.weekly,distinct=True)}}
{{priceMax= prices.last()}}
* {{=priceMax.weekly}}*
</div>
{{pass}}
it throws exception error
<type 'exceptions.AttributeError'>('NoneType' object has no attribute
'weekly')
Funny enough if I place this outside for loop and specify id, it works
{{prices=db((db.price.id>0) &
(*db.price.listing==2*)).select(db.price.weekly,distinct=True)}}
{{priceMax= prices.last()}}
{{=priceMax.weekly}}
{{for item...
####Rresult###
100.00
Sorry for the lengthy post but I wanted to make it as clear as possible what
I'm trying to achieve here,on the another hand If it's not clear... double
sorry :) Also, I'm not too happy to place this logic in view, but so far it
seems most simpler way to accomplish desired result, I'm open to better
suggestions where all logic is in controller.
Thanks
IK