Documentation here: http://web2py.com/books/default/chapter/29/6#find,-exclude,-sort (though it appears the "reverse" argument isn't documented).
Anthony On Wednesday, May 23, 2012 9:13:24 AM UTC-4, Anthony wrote: > > Sorry, I misunderstood what you were trying to do. I thought you wanted to > sort by date submitted and then by views, but you simply want to select the > 5 most recently submitted and then sort those 5 by views only. To do that, > first select the 5 most recent, and then use the Rows.sort() method: > > rows=db().select(db.Article.ALL, orderby=~db.Article.Submitted, limitby=(0 > ,5)).sort(lambda row: > row.Views, reverse=True) > > Anthony > > On Wednesday, May 23, 2012 8:52:00 AM UTC-4, BlueShadow wrote: >> >> >> I had finally some time to do my minimal site which shows the problem. >> Thanks everyone for your help and support. >> >> >> On Sunday, May 13, 2012 3:25:32 PM UTC+2, Anthony wrote: >>> >>> Hmm, I tried a similar query and it properly respects both ~'s. Can you >>> pack and attach a minimal app (using SQLite) that exhibits the problem? >>> >>> Anthony >>> >>> On Sunday, May 13, 2012 9:14:27 AM UTC-4, BlueShadow wrote: >>>> >>>> >>>> def index(): >>>> rows=db().select(db.article.ALL, orderby=~db.article.submitted|~db >>>> .article.views, limitby=(0,5)) >>>> return dict(Articles=rows) >>>> >>>> Thats my code from the default.py >>>> removing and adding the second ~ doesn't change anything. >>>> in my index.htm I simply print the Titles and views with a for loop. >>>> >>>> >>>> On Sunday, May 13, 2012 3:03:30 PM UTC+2, Anthony wrote: >>>>> >>>>> orderedby=~db.article.date|~db.article.views >>>>> >>>>> should work. Did you try exactly that code? >>>>> >>>>> Anthony >>>>> >>>>> On Sunday, May 13, 2012 4:43:24 AM UTC-4, BlueShadow wrote: >>>>>> >>>>>> Hi I got A table for articles on my page wich contains a variable for >>>>>> the date it was submitted and the number of views (content title...) >>>>>> I tried to do a select which gives me the newest five of this table >>>>>> (orderedby=~article.date) Now I want to sort those five by the number of >>>>>> views. >>>>>> I tried it with appending the ordered by with |article.views and with >>>>>> |~article.views but the result is the same I get the newest five sorted >>>>>> by >>>>>> views but with the least views first. >>>>>> I know I could reverse the order with some lines of python code but >>>>>> there must be a simple way to do it. >>>>>> >>>>>