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函数填充,所以我只需添加该字段定义。再一次,谢谢! –