Created
September 8, 2021 14:01
-
-
Save ciscoinfo/6d4f0c6fccc82411c8a881a39523a54e to your computer and use it in GitHub Desktop.
article Flask (Python) : lire une requête PUT / POST - models 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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