[Answered ]-How do I properly nest serializers in Django REST Framework?

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
            }

Leave a comment