I am writing a web application using rest_framework_gis. One of my models has 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'
Then I serialize it with 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', )
And finally my views:
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
My question is what kind of data do I input into location field? I know it should be in JSON format. But what exactly do I write? If anyone could give an example it would be really helpful
Oh boy, this is embarrassing. Found the answer on GitHub repository of django-rest-framework-gis The correct example is like this:
Hope, this helps to those who were searching