지형 거리 검색에 TastyPie를 사용하고 있습니다. TastyPie가 공식적으로 지원하지 않기 때문에 약간 어렵습니다. Github에서 (https://gist.github.com/1067176)에 다음 코드 샘플 발견Django TastyPie Geo 거리 검색
def apply_sorting(self, objects, options=None):
if options and "longitude" in options and "latitude" in options:
return objects.distance(Point(float(options['latitude']), float(options['longitude']))).order_by('distance')
return super(UserLocationResource, self).apply_sorting(objects, options)
그것은 잘 작동을하지만, 지금은 TastyPie의 필드 결과로 거리를 가지고 싶습니다. 어떻게 할 생각인가? fields 속성에 "distance"를 포함하면 작동하지 않습니다.
미리 도움 주셔서 감사합니다.
그게 효과가 있습니다! 너무 고마워, 정확히 내가 원했던거야! 이 값은 실제로 .distance() geodjango 함수로 채워지므로 해당 필드 정의를 추가해야합니다. 다시 한번 감사드립니다! –