I have a model containing latitude and longitude information like FloatFields.
class Trader(models.Model): latitude = models.FloatField() longitude = models.FloatField()
I would like to order this model at a greater distance from the given position (lat, lon), but it may not seem like this using F () expressions (using the haversine library, I was unable to convert them to float numbers)
Trader.objects.all().annotate(distance=haversine((lat, lon), (float(F('latitude')), float(F('longitude'))))).order_by('distance')
This request throws the following TypeError:
float() argument must be a string or a number
I also tried using ExpressionWrapper with the FloatField () argument as output_field without success.
How could I achieve this?
Thank you in advance for your help!
source share