File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed
project/03-items-stores-smorest Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change 11from 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
1720class 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 )
You can’t perform that action at this time.
0 commit comments