Skip to content

4. Serializers

Carlos Aguilar edited this page May 16, 2018 · 1 revision

/testapi/quickstart/serializers.py

class PointSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Point
        fields = ('x', 'y')

Here, we can find some serializers that we'll use for our data representations in communications with the API endpoints.

Note that we are specifying the model which we are serializing and the fields from that model used to build the serialized JSON objects.

We've used the HyperlinkedModelSerializer to build hyperlinked relations in this case. We could have used the primary key and various other relationships, but hyperlinking is a good RESTful design.

Clone this wiki locally