| ▲ | ErroneousBosh a day ago | |||||||
> The one thing I really appreciate with the ORM is that you really can get the ORM to make... more or less any sort of SQL query you want. And if you can't make the ORM make the SQL query you want, you can just write it as a SQL query, like this godawful monstrosity:
... which calculates the Haversine distance from where you are now to the five nearest points.I am in roughly equal parts proud of and horrified by this creation. | ||||||||
| ▲ | rtpg a day ago | parent | next [-] | |||||||
Site.objects.annotate( distance=Degrees(ACos(Cos(.....))), latpoint=float(lat), lngpoint=float(lon), ).order_by("distance")[:5] for function calls, look at django.db.models.functions, you can find a bunch of stuff in there or create custom ones super easily (like "two lines of codes" easily) I mean you have a thing that works in theory so it's a bit of navel gazing, though. | ||||||||
| ||||||||
| ▲ | ranger_danger a day ago | parent | prev [-] | |||||||
I'm not seeing anything that can't be done here without using raw() though? | ||||||||
| ||||||||