> The one thing I really appreciate with the ORM is that you really can get the ORM to make... more or less any sort of SQL query you want.
And if you can't make the ORM make the SQL query you want, you can just write it as a SQL query, like this godawful monstrosity:
x = Site.objects.raw("select id, name, lat, lon, 111.045*degrees(acos(cos( \
radians(latpoint))*cos(radians(lat)) \
*cos(radians(lngpoint)-radians(lon)) \
+sin(radians(latpoint))*sin(radians(lat)))) \
as distance from sites_site join \
(select %s as latpoint, %s as lngpoint) as p on 1=1 \
order by distance limit 5", [float(lat), float(lon)])
... which calculates the Haversine distance from where you are now to the five nearest points.I am in roughly equal parts proud of and horrified by this creation.