3
我使用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。你有什麼想法如何做到這一點?只在字段屬性中包含「距離」不起作用。
在此先感謝您的幫助!
工作!非常感謝,這正是我想要的!該值實際上由.distance()geodjango函數填充,所以我只需添加該字段定義。再一次,謝謝! –