Python 无法解析关键字';距离';到田野里去。选项包括:店铺类别、地址、距离、id、名称、店铺位置、用户、用户id

Python 无法解析关键字';距离';到田野里去。选项包括:店铺类别、地址、距离、id、名称、店铺位置、用户、用户id,python,django,django-haystack,geodjango,django-filters,Python,Django,Django Haystack,Geodjango,Django Filters,我有两个模型店和客户 商店 顾客 我想在商店里设置过滤器。店铺将向客户显示店铺与客户之间的距离是否低于店铺给出的距离。距离 还有我的观点 from django.contrib.gis.db.models.functions import Distance Shop_list = Shop.objects.filter( distance_gte=Distance('shop_location', request.user.customer.customer_loca

我有两个模型店和客户

商店 顾客 我想在商店里设置过滤器。店铺将向客户显示店铺与客户之间的距离是否低于店铺给出的距离。距离 还有我的观点

from django.contrib.gis.db.models.functions import Distance
  Shop_list = Shop.objects.filter(
    distance_gte=Distance('shop_location',    
    request.user.customer.customer_location)
)

我发现错误,无法将关键字“距离”解析到字段中。选择包括:店铺类别、地址、距离、id、名称、店铺位置、用户、用户id

您需要使用双下划线进行查找,因此:

from django.contrib.gis.db.models.functions import Distance

Shop_list = Shop.objects.filter(
    distance__gte=Distance(
        'shop_location',    
        request.user.customer.customer_location
    )
)
来自django.contrib.gis.db.models.functions导入距离
Shop\u list=Shop.objects.filter(
距离=距离(
“店铺位置”,
request.user.customer.customer\u位置
)

)
距离字段在
商店
中的确切作用是什么?这是到什么的距离?商店给出的距离,在此距离下我将向客户显示,但这不是特定于
商店的数据,也不是应该保留的数据。我如何做到这一点?如果我想把所有的商店打印给那些在商店给出的距离之内的客户,我在商店里有更多的数据,但我认为没有必要写,我已经写了那些necessary@alltypenews:您将其除以千,因此距离(..)/1000
。如果您有任何其他建议,请帮助我,我请求你
from django.contrib.gis.db.models.functions import Distance
  Shop_list = Shop.objects.filter(
    distance_gte=Distance('shop_location',    
    request.user.customer.customer_location)
)
from django.contrib.gis.db.models.functions import Distance

Shop_list = Shop.objects.filter(
    distance__gte=Distance(
        'shop_location',    
        request.user.customer.customer_location
    )
)