Jonathan,

When I started with web2py I tried to use different names, as per book, but 
it would throw name error as items wasn't specified (<type 
'exceptions.NameError'>(name 'items' is not defined)) and I stayed with 
first thing that worked for me i.e. item in item. Thanks for that, now when 
I think about it makes sense; variable passed from controller function 
should be placed second in for loop (talking about going back to basics) :).


Anthony,

Thanks for the advices, some of them were just my  mistakes/typo, for rest 
I'll implement as you suggested. I should know better, by reading so many 
posts in this group, to use actual code, but I wanted to make it as simple 
as possible... My real issue was/is, how to display that one record without 
web2py adding extra syntax to the result. e.g. <Row....

I tried your suggestion, but it would still throw the same error.

so:

{for item in items:}}     ### item in controller is changed to items
    Listing {{=item.title}} max price

            
{{prices=db(db.price.listing==item.id).select(orderby=db.price.weekly,distinct=True)}}
 

                {{=prices.last().weekly}}
            

<type 'exceptions.AttributeError'>('NoneType' object has no attribute 
'weekly') 

But this

            
{{prices=db(db.price.listing==item.id).select(orderby=db.price.weekly,distinct=True)}}
 

                {{=prices.last()}}

doesn't throw any errors but problem is how data is displayed: all fields in 
this format

*<Row {'weekly': Decimal('100.00')}....*

instead of 100.00


> Are the prices inserted in order, so the last is always the max?
Sorry, I didn't include in original code orderby. If I specify  orderby in 
select() and by using last() function, it would display biggest number or 
with .first() smallest number. maybe a chaet not to use use min max 
functions.

I was playing with .min() and .max() functions ,but couldn't find 
appropriate usage example for my requirements and I was getting similar 
result. 

I should mention that if second for loop  (nested) is used instead. I'm 
getting proper output, but problem is that all weekly records are displayed 
and not one (biggest or smallest number).

e.g.
{{for item in items:}}
            
{{prices=db(db.price.listing==item.id).select(orderby=db.price.weekly,distinct=True)}}
 

            {{for price in prices:}}
                {{=price.weekly}}
            {{pass}}    
{{pass}}


Cheers
IK


Reply via email to