Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am newbie to django and developing rest api using Django rest framework gis. Previously i was using sql query for transform geometry

SQL
select id,name,round(value::numeric,2) as value, st_transform(geometry, 3857) as geometry from my_model


Python
class MyModel(models.Model):
    name = models.CharField(max_length=50, blank=True)
    value = models.FloatField()
    geometry = models.GeometryField(null=True, blank=True)


    class Meta:
        db_table = u'my_model'

    def __unicode__(self):
        return '%s' % self.name


Here selrializer class

Python
class MyModelSerializer(serializers.GeoModelSerializer):
    class Meta:
        model = MyModel
        fields = ('id', 'name', 'value', 'geometry')


I have also tried to do this way but cannot transform output

PHP
class MyModelViewSet(viewsets.ModelViewSet):

    queryset = MyModel.objects.all().transform(3857)
    serializer_class = MyModelSerializer


How can i do this in django rest framework gis?

Where can i get queries sample or comprehensive tutorial for rest framework gis?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900