2👍
✅
The simplest approach would be to add a latlng field to the Building serializer and implement a method to retrieve it:
class BuildingSerializer(serializers.ModelSerializer):
class Meta:
model = Building
latlng = serializers.SerializerMethodField()
def get_latlng(self, obj):
if obj.address and obj.address.latlng:
return {
"type": obj.address.latlng.geom_type,
# any other fields in latlng
}
Source:stackexchange.com