UserSchema Design
Now we have learned why we need to use Schema
and how we can define a schema, we will start to work on that in our Smilecook
application. In the case of user registration, we will expect the user to fill in their information on a web form, and then send the details in JSON format to the server. Our Smilecook
application will then deserialize it to be a User
object, which can be worked on in our application.
We will, therefore, need to define a UserSchema
class to specify the expected attributes in the JSON request coming from the frontend. We will need the following fields:
id
: Usefields.Int()
to represent an integer. In addition,dump_only=True
means that this property is only available for serialization, not deserialization. This is becauseid
is autogenerated, not passed in by the user.username
: Usefields.String()
to represent a string and applyrequired=True
to indicate that this property is mandatory. When the client sends JSON data without...