On Dec 31, 2011, at 7:41 PM, sungchi wrote: > As an alternative, > > news=db(db.news.post_time>(now-2592000.0)).select() if > sort=='hot': news=news.sort(lambda row: ~row.hotness) > [limitby[0]:limitby[1]] if sort=='score': > news=news.sort(lambda row: ~row.score)[limitby[0]:limitby[1]] > > However, this error has occurred. (hotness filed is 'double') > TypeError: bad operand type for unary ~: 'float'
Try sorting -row.hotness. > > On 1월1일, 오후12시17분, Jonathan Lundell <jlund...@pobox.com> wrote: >> On Dec 31, 2011, at 5:17 PM, sungchi wrote: >> >>> If I do that "limitby" range is only in the sort. >>> I want to sort on the entire range. >> >> You're right. I can't think of a way to do it in one pass. >> >> >> >> >> >> >> >> >> >>> On 1월1일, 오전9시17분, Jonathan Lundell <jlund...@pobox.com> wrote: >>>> On Dec 31, 2011, at 4:07 PM, sungchi wrote: >> >>>>> Thanks Jonathan! >> >>>>> But, sort() function When using the "limitby" using the "pagination" >>>>> to be harder. >> >>>> True. What if you order by (post_time, score) in the request, and then >>>> re-sort the result? >> >>>>> On 1월1일, 오전2시11분, Jonathan Lundell <jlund...@pobox.com> wrote: >>>>>> On Dec 31, 2011, at 8:46 AM, sungchi wrote: >> >>>>>>> now=time.time() >>>>>>> sorts={ >>>>>>> 'hot':~db.news.hotness, >>>>>>> 'score:~db.news.score, >>>>>>> 'new':~db.news.post_time} >>>>>>> orderby=sorts[sort] >>>>>>> limitby=(50,101) >>>>>>> news =db(db.news.post_time>(now-25922000.0)).select(limitby=limitby, >>>>>>> orderby=orderby) >> >>>>>>> Traceback (most recent call last): >>>>>>> File "/Users/web2py/gluon/restricted.py", line 204, in restricted >>>>>>> exec ccode in environment >>>>>>> File "/Users/web2py/applications/feed9/controllers/default.py", line >>>>>>> 352, in <module> >>>>>>> File "/User/web2py/gluon/globals.py", line 162, in <lambda> >>>>>>> self._caller = lambda f: f() >>>>>>> File "/Users/web2py/applications/feed9/controllers/default.py", line >>>>>>> 123, in index >> >>>>>>> news=db(db.news.post_time>(now-2592000.0)).select(limitby=limitby,orderby=o >>>>>>> rderby) >>>>>>> File "/Users/web2py/gluon/dal.py", line 6330, in select >>>>>>> return self.db._adapter.select(self.query,fields,attributes) >>>>>>> File "/Users/web2py/gluon/dal.py", line 3463, in select >>>>>>> (items, tablename, fields) = >>>>>>> self.select_raw(query,fields,attributes) >>>>>>> File "/Users/sungchi9/Dropbox/python/web2py/gluon/dal.py", line >>>>>>> 3458, in select_raw >>>>>>> items = items.fetch(limit, offset=offset) >>>>>>> File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/ >>>>>>> GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ >>>>>>> google/appengine/ext/db/__init__.py", line 2084, in fetch >>>>>>> return list(self.run(limit=limit, offset=offset, **kwargs)) >>>>>>> File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/ >>>>>>> GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ >>>>>>> google/appengine/ext/db/__init__.py", line 2001, in run >>>>>>> raw_query = self._get_query() >>>>>>> File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/ >>>>>>> GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ >>>>>>> google/appengine/ext/db/__init__.py", line 2357, in _get_query >>>>>>> query.Order(*self.__orderings) >>>>>>> File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/ >>>>>>> GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ >>>>>>> google/appengine/api/datastore.py", line 1398, in Order >>>>>>> (orderings[0][0], self.__inequality_prop)) >>>>>>> BadArgumentError: First ordering property must be the same as >>>>>>> inequalityfilterproperty, if specified for thisquery; received >>>>>>> score, expected post_time >> >>>>>>> what's wrong? why not post_timefilterwithorderbyargument? >> >>>>>> http://code.google.com/appengine/docs/java/datastore/queries.html#Res... >> >>>>>>> If aqueryhas both afilterwith an inequality comparison and one or more >>>>>>> sort orders, thequerymust include a sort order for the property used in >>>>>>> the inequality, and the sort order must appear before sort orders on >>>>>>> other properties. >> >>>>>> Just sort the result in code.