GeoDjango 如何在此查询中以米为单位显示距离

GeoDjango how to display distance in meters in this query

GeoDjango 如何在此查询中显示以米为单位的距离

现在我只是按距离排名显示它们。

我更想得到以米为单位的距离

models.py

class Master(models.Model):
    city_master = models.ForeignKey(myCity, on_delete=models.CASCADE, null=True, blank=True, verbose_name="cityName", db_index=True, related_name="CityName_relate")
    country_master = models.ForeignKey(CountryMy, on_delete=models.CASCADE, null=True, blank=True, verbose_name="countryName", db_index=True, related_name="CountryMyName_relate")
    name = models.CharField(blank=True, null=True, max_length=3000)
    point = models.PointField(blank=True, null=True)

views.py

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

class MainList(View):
.....

    def get(self, request):
   ........

        current_location = BaseUrl.objects.get(Country__nameCountry_for_sites=str(country)).point

        main_masters_in_country = myCity.objects.filter(
            point__distance_lte=((current_location, D(km=50)))).annotate(
            distance=Distance('point', current_location)).order_by('distance')[:5]



       return render(request, self.template_name, context={'main_masters_in_country': main_masters_in_country}, )

我更想得到以米为单位的距离

谢谢朋友/谢谢朋友/Gracias amigos/Danke Freunde/Merci les amis/धन्यवाद दोस्तों/Спасибо друзья

这与这个问题类似(但认为不是直接重复):

Django 的 Distance documentation 声明如下:

Because the distance attribute is a Distance object, you can easily express the value in the units of your choice. For example, city.distance.mi is the distance value in miles and city.distance.km is the distance value in kilometers. See Measurement Objects for usage details and the list of Supported units. quote

因此,为了以米为单位表示距离,您可以按如下方式修改查询:

(...).annotate(
    distance=Distance('point', current_location).m
).order_by('distance')[:5]