Managing serialization and deserialization with relationships and hyperlinks
Our new RESTful Web API has to be able to serialize and deserialize the GameCategory
, 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 the other classes will inherit from the rest_framework.serializers.HyperlinkedModelSerializer ...
Get Building RESTful Python Web Services now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.