Skip to content

Instantly share code, notes, and snippets.

@ciscoinfo
Created September 8, 2021 14:01
Show Gist options
  • Save ciscoinfo/6d4f0c6fccc82411c8a881a39523a54e to your computer and use it in GitHub Desktop.
Save ciscoinfo/6d4f0c6fccc82411c8a881a39523a54e to your computer and use it in GitHub Desktop.
article Flask (Python) : lire une requête PUT / POST - models 1
class ProductSchema(Schema):
id = fields.Int()
name = fields.Str()
price = fields.Float()
description = fields.Str(allow_none=True)
@post_load
def make_product(self, data, **kwargs):
constructor_helper = {k: v for k, v in data.items() if v != None}
return Product(**constructor_helper)
product_schema = ProductSchema()
products_schema = ProductSchema(many=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment