I’d like to order an “Event” queryset by “distance” for each individual query
Given the following, how can I pull it off?
class Venue(models.Model):
latitude = models.FloatField(max_length=10)
longitude = models.FloatField(max_length=10)
def distance(self, query_coordinates):
"Calculates distance on a query by query basis"
venue_coords = self.latitude, self.longitude
distance_to_venue = distance.distance(query_coordinates, house_coords) # a function which outputs distance in miles
return distance_to_venue
class Event(models.Model):
venue = models.ForeignKey(Venue, related_name='shows')
I’ve been pouring over the annotate docs after reading some related stackoverflow questions, but can’t figure out how to get it to work for my situation. How can I do this efficiently??
Thanks in advance.
You can’t pull it off, django doesn’t support ordering by model methods.
For working with geo-spatial data try GeoDjango (http://docs.djangoproject.com/en/dev/ref/contrib/gis/).