2👍
The issue here is that you are trying to sort the queryset based on a nonexistent field named distance
. You should annotate them using Distance()
function first:
from django.contrib.gis.db.models.functions import Distance
Address.objects.filter(...).annotate(distance=Distance("location", current_point).order_by("distance")
Source:stackexchange.com