-
Book Overview & Buying
-
Table Of Contents
Building RESTful Python Web Services
By :
The GameSerializer class declares many attributes with the same names that we used in the Game model and repeats information, such as the types and the max_length values. The GameSerializer class is a subclass of rest_framework.serializers.Serializer, it declares attributes that we manually mapped to the appropriate types and overrides the create and update methods.
Now, we will create a new version of the GameSerializer class that will inherit from the rest_framework.serializers.ModelSerializer class. The ModelSerializer class automatically populates both set of default fields and a set of default validators. In addition, the class provides default implementations for the create and update methods.
In case you have any experience with Django Web Framework, you will notice that the Serializer and ModelSerializer classes are similar to the Form and ModelForm classes.
Now, go to the gamesapi/games folder and open the serializers.py file...