Skip to content

Instantly share code, notes, and snippets.

@smaillns
Created January 1, 2022 00:08
Show Gist options
  • Save smaillns/c4f63477a0ebbe35d08ed947fb2863cf to your computer and use it in GitHub Desktop.
Save smaillns/c4f63477a0ebbe35d08ed947fb2863cf to your computer and use it in GitHub Desktop.
Marshmallow schemas
from marshmallow import Schema, fields
class AuthorSchema(Schema):
id = fields.Int(required=True)
name = fields.Str(required=True)
gender = fields.Str(required=True)
created_at = fields.Date()
updated_at = fields.Date()
class BookSchema(Schema):
id = fields.Int(required=True)
created_at = fields.Date()
updated_at = fields.Date()
title = fields.Str(required=True)
author = fields.Nested(AuthorSchema, many=False)
class CreateBookSchema(Schema):
title = fields.Str(default=None)
author_id = fields.Int(required=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment