Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

Commit

Permalink
added shonky SQL statement, not currently using it
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Willison committed Sep 12, 2009
1 parent 8e180ac commit 687fa84
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions djangopeople/models.py
Expand Up @@ -124,8 +124,25 @@ def irc_nick(self):
return '<none>'

def get_nearest(self, num=5):
"Returns the nearest X people, but only within the same continent"
# TODO: Add caching
"Returns the nearest X people"
# TODO: use this shonky SQL query instead of the other shonky method
# From http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html
sql = """
SELECT id, (
3959 * acos(
cos(radians(%(latitude)s)) *
cos(radians(latitude)) *
cos(
radians(longitude) - radians(%(longitude)s)
)
+ sin(radians(%(latitude)s)) *
sin(radians(latitude))
)
) AS distance
FROM djangopeople_djangoperson
HAVING distance < 100 ORDER BY distance LIMIT 0, %(num)s
"""
# To search by kilometers instead of miles, replace 3959 with 6371.

people = list(self.country.djangoperson_set.select_related().exclude(pk=self.id))
if len(people) <= num:
Expand Down

0 comments on commit 687fa84

Please sign in to comment.