I have a model containing latitude and longitude information as FloatFields.
class Trader(models.Model):
latitude = models.FloatField()
longitude = models.FloatField()
I would like to order this model by an increasing distance from a given position(lat, lon) but can't seem to do so using F() expressions (using haversine library, I haven't succeeded in transforming them into float numbers)
Trader.objects.all().annotate(distance=haversine((lat, lon), (float(F('latitude')), float(F('longitude'))))).order_by('distance')
This query throws the following TypeError :
float() argument must be a string or a number
I have also tried using ExpressionWrapper with a FloatField() as output_field argument, without success.
How could I achieve that ?
Thank you in advance for any help !