I am working with Django DRF and GeoDjango for a simple model which is as follows.
class Company(models.Model):
name = models.CharField(max_length=200, default='Company', null=True)
def __unicode__(self):
return self.name
class Shop(models.Model):
name = models.CharField(max_length=200, default="bla")
address = models.CharField(max_length=300, default='blabla')
location = models.PointField(null=True, blank=True, geography=True)
company = models.ForeignKey(
Company, on_delete=models.CASCADE, null=True)
This is its serializer.py
class ShopSerializer(serializers.ModelSerializer):
distance = serializers.DecimalField(
source='distance.km', max_digits=10, decimal_places=2, required=False, read_only=True)
class Meta:
model = Shop
fields = ['id', 'name', 'address', 'location', 'distance']
# read_only_fields = ['distance']
class CompanySerializer(serializers.ModelSerializer):
shop_set = ShopSerializer(many=True)
class Meta:
model = Company
fields = ['id', 'name', 'shop_set']
def create(self, validated_data):
shop_validated_data = validated_data.pop('shop_set')
company = Company.objects.create(**validated_data)
shop_set_serializer = self.fields['shop_set']
for each in shop_validated_data:
each['company'] = company
shops = shop_set_serializer.create(shop_validated_data)
return company
everything works fine until I add rest_framework_gis
in my settings.py file or add the following line in my shop serializer
serialize('geojson', Shop.objects.all(),
geometry_field='location', fields=('name', 'address'))
In both the cases get GDALException OGR failure. I have checked my versions of GDAL and Python. Both are 64 bit. And both python and GDAL are working fine.
What I basically need to do here is to convert my POINT field into json lat long response right now the response is as such (if i do not include the lines that cause error).
{
"id": 1,
"name": "Cosmetica",
"address": "somwhere",
"location": "SRID=4326;POINT (24.896 67.182)"
}
Please help.