Django Sort By Calculated Field
问题 Using the distance logic from this SO post, I'm getting back a properly-filtered set of objects with this code: class LocationManager(models.Manager): def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True): if use_miles: distance_unit = 3959 else: distance_unit = 6371 from django.db import connection, transaction cursor = connection.cursor() sql = """SELECT id, (%f * acos( cos( radians(%f) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(