开发者

order("-modified") with geomodel

Edit: Solved using key=lambda and learning what I'm actually doing.

With ge开发者_如何转开发model like

class A(GeoModel,search.SearchableModel):

I'm trying to order by date using db.GeoPt to store google maps coordinates with GAE and geomodel I can map and match. But order("- modified") is not working. There is no trace. All ideas are welcome. The code that should sort is

a = A.proximity_fetch(A.all().filter("modified >",
timeline).filter("published =", True).filter("modified <=",
bookmark ).order("-modified") ,db.GeoPt(lat, lon),max_results=PAGESIZE
+1, max_distance=m)

All parameters appear to work except order("-modified")

Trying the suggested way sorting with lambda I get message "TypeError: lambda() takes exactly 1 argument (2 given)"

a = A.proximity_fetch(A.all().filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark ).order("-modified") ,db.GeoPt(lat, lon),max_results=40, max_distance=m)
a = sorted(a, lambda x: x.modified, reverse=True)


GeoModel sorts the result of the nearest to the farthest of the point. You need to sort your result with python after have executed proximity_fetch:

result = sorted(result, key=lambda x: x.modified, reverse=True)

Edited: forget to use the 'key' argument's for sorted


GeoModel performs multiple queries and combines the results into a single resultset. Each query should be executed with your sort order, but the end results may not be sorted according to that order. Sorting the results in memory is probably sufficient to overcome this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜