Managing serialization and deserialization with relationships and hyperlinks
Our new RESTful Web API has to be able to serialize and deserialize the EsrbRating
, Game
, Player
, and PlayerScore
instances into JSON representations. In this case, we also have to pay special attention to the relationships between the different models when we create the serializer classes to manage serialization to JSON and deserialization from JSON.
In our last version of the previous API, we created a subclass of the rest_framework.serializers.ModelSerializer
class to make it easier to generate a serializer and reduce boilerplate code. In this case, we will also declare a class that inherits from ModelSerializer
but three classes will inherit from the rest_framework.serializers.HyperlinkedModelSerializer
class.
HyperlinkedModelSerializer
is a type of ModelSerializer
that uses hyperlinked relationships instead of primary key relationships, and therefore, it represents the relationships to other model instances with...