For a given user, I'm trying to find out the other users who drive closest to them. For carpooling.
Here are my abbriviated models:
class Office(models.Model):
location = PointField(srid=4326, geography=True)
class User(models.Model):
office = fk(Office)
home_location = PointField(srid=4326, geography=True)
In my head, I need to do a few things:
- Annotate on a
LineStringField
ofF('home_location')
→F('office__location')
to represent an as-the-crow-flies route to work. - Annotate on the shortest distance for each route from the given user's
home_location
. - Sort by that distance, desc.
It looks simple on paper but I'm stumbling at the first hurdle. How do I annotate on a LineStringField
?
This seems like it would be a very common problem for anybody using GIS in Django.