Hii I trying to run the Haversine formula on the MariaDB base on my model
the model is
class MeteorologicalSite(models.Model):
lat = models.DecimalField("Latitude", max_digits=17, decimal_places=15)
lon = models.DecimalField("Longitude", max_digits=17, decimal_places=15)
class Site(models.Model):
lat = models.DecimalField("Latitude", max_digits=17, decimal_places=15)
lon = models.DecimalField("Longitude", max_digits=17, decimal_places=15)
and this is the Haversine function
def Haversine_formula(self, site):
from django.db.models.functions import Cos, Sin, ASin, Sqrt, Radians
lat1 = Radians(site.lat)
lon1 = Radians(site.lon)
lat2 = Radians(F("lat"))
lon2 = Radians(F("lon"))
r = 6372.8
sql_haversine_formula = 2 * r * ASin(
Sqrt(
Sin((lat1-lat2)/2)**2+
Cos(lat1)*
Cos(lat2)*
Sin((lon1 - lon2)/2)**2
)
)
MeteorologicalSite.objects.filter(radiation=True)\
.annotate(mycolumn=sql_haversine_formula)
and it doesn't run it return <django.db.models.query.QuerySet object at 0xffff57b99ca0>
I tried to use lat and lon for 1 and 2 as Decimal directly and it still doesn't work
so I understand that my problem is in the way I use annotate or in me sql_haversine_formula
Does anyone have an idea why this does not work?
sorry for my English