views:

43

answers:

2

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

With gemodel 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)
+3  A: 

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.

Nick Johnson
Thank you Nick for the information. I'm trying to sort in memory instead.
LarsOn
+2  A: 

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

sahid
Many thanks! I'm trying this way getting message TypeError: <lambda>() takes exactly 1 argument (2 given) glad having a trace now
LarsOn
Yes my apologise i have make an error. The declaration of sorted is `sorted(iterable[, cmp[, key[, reverse]]])` So, you're right, you need to use 'key=lambda'.
sahid