Skip to content

Commit 0beccc3

Browse files
committed
🎨 (Marshmallow) Improve naming of schemas in Smorest section
We still need to update the e-book to show the new names.
1 parent ea91a0e commit 0beccc3

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
from marshmallow import Schema, fields
22

33

4-
class ItemSchema(Schema):
5-
id = fields.Str(dump_only=True)
4+
class PlainItemSchema(Schema):
5+
id = fields.Int(dump_only=True)
66
name = fields.Str(required=True)
77
price = fields.Float(required=True)
8-
store_id = fields.Int(required=True)
98

109

11-
class ItemWithoutStoreSchema(Schema):
12-
id = fields.Str(dump_only=True)
13-
name = fields.Str(required=True)
14-
price = fields.Float(required=True)
10+
class PlainStoreSchema(Schema):
11+
id = fields.Int(dump_only=True)
12+
name = fields.Str()
13+
14+
15+
class ItemSchema(PlainItemSchema):
16+
store_id = fields.Int(required=True, load_only=True)
17+
store = fields.Nested(lambda: PlainStoreSchema(), dump_only=True)
1518

1619

1720
class ItemUpdateSchema(Schema):
1821
name = fields.Str()
1922
price = fields.Float()
2023

2124

22-
class StoreSchema(Schema):
23-
id = fields.Str(dump_only=True)
24-
name = fields.Str(required=True)
25-
26-
27-
class StoreWitoutItemsSchema(Schema):
28-
id = fields.Str()
29-
name = fields.Str()
25+
class StoreSchema(PlainStoreSchema):
26+
items = fields.List(fields.Nested(PlainItemSchema()), dump_only=True)

0 commit comments

Comments
 (0)