我正在使用 rest_framework_gis 编写一个 Web 应用程序。我的一个模型有 PointField
from django.contrib.gis.db import models
from django.contrib.auth import get_user_model
User = get_user_model()
class Avatar(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='avatar')
location = models.PointField(srid=4326)
def __str__(self):
return self.user.username + '\'s avatar'
然后我用 GeoFeatureModelSerializer 序列化它
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from .models import Avatar
class AvatarSerializer(GeoFeatureModelSerializer):
class Meta:
model = Avatar
geo_field = 'location'
auto_bbox = True
fields = ('location', )
最后是我的观点:
from .models import Avatar
from .serializers import AvatarSerializer
from rest_framework_gis.filters import DistanceToPointFilter
class AvatarViewSet(viewsets.ModelViewSet):
queryset = Avatar.objects.all()
serializer_class = AvatarSerializer
distance_filter_field = 'geometry'
filter_backends = (DistanceToPointFilter, )
bbox_filter_include_overlapping = True
我的问题是我应该在位置字段中输入什么样的数据?我知道它应该是 JSON 格式。但我到底要写什么呢?如果有人可以举个例子,那将非常有帮助