Our RESTful web API has to be able to serialize the game instances into JSON representations and also deserialize the JSON representations to build game instances. With Django REST Framework, we just need to create a serializer class for the game instances to manage serialization to JSON and deserialization from JSON.
Note
Django REST Framework uses a two-phase process for serialization. The serializers are mediators between the model instances and Python primitives. Parsers and renderers act as mediators between Python primitives and HTTP requests and responses.
We will configure our mediator between the Game
model instances and Python primitives by creating a subclass of the rest_framework.serializers.Serializer
class to declare the fields and the necessary methods to manage serialization and deserialization. We will repeat some of the information about the fields that we have included in the Game
model so that we understand all the things that we...