How to find nearby objects in Django, based on location. It seems annotate does not consider model fields

Viewed 32

I am trying find nearby objects in Django based on location.

I have used this query:

near_objs = MyModel.objects.all().annotate(distance=great_circle((given_latitude, given_longitude), (F('latitude'), F('longitude'))).km)

But I am getting error float() argument must be a string or a number, not 'F'.

If I don't useF(), it throws errorValueError: could not convert string to float: 'latitude'

It seems annotate() does not consider ('latitude') and ('longitude') as model fields

0 Answers
Related