[Answer]-Geodjango foreignkey by distance

1👍

You would need something like this:

Show.representation_set.distance(user.geoloc, field_name='venue__coords') \
                       .order_by('distance')

Unfortunately reversed one to one or one to many relationships are not supported with GeoQuerySet methods (including distance). I already created a feature request ticket for this.

So for now I think you’re stuck with:

  • some hack in Python, not always efficient (like you wrote)
  • using raw sql queries

Leave a comment