我想在 SQL 命令之后对 QuerySet 进行排序。
resultSet = PoiRestauration.objects.raw(' \
WITH point as( \
SELECT ST_Transform(GeomFromText(\'POINT(%s %s)\',4326),900913) as geom \
) \
SELECT \
osm_id, way, type, amenity, name, cuisine, website, phone \
FROM \
poi_restauration, \
point \
WHERE \
way && st_expand(geom,100000) \
ORDER BY \
st_length(ST_ShortestLine(way,geom)) ASC \
LIMIT 5', [float(lon), float(lat)])
for object in resultSet:
object.way.transform(4326)
osrm = getOsrmRoute([str(lat)+","+ str(lon),str(object.way.y)+","+str(object.way.x)],"car",True)
object.osrmDistance = osrm['distance']
object.osrmGeometry = osrm['geometry']
print object.osrmDistance
对于我的结果集中的每个点,我计算一个地理距离。现在,我想对这些距离进行排序,但不能使用 QuerySet 来完成。我有这个错误:
TypeError: 'PoiRestauration' object does not support indexing
当我尝试使用这样的东西时:
print sorted(resultSet, key=lambda poi:poi[2])
感谢和问候