-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
56 lines (36 loc) · 1.55 KB
/
schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from marshmallow import Schema, fields
class PlainProductSchema(Schema):
id = fields.Str(dump_only=True)
name = fields.Str(required=True)
price = fields.Float(required=True)
class ProductUpdateSchema(Schema):
name = fields.Str()
price = fields.Float()
store_id = fields.Str()
class PlainStoreSchema(Schema):
id = fields.Str(dump_only=True)
name = fields.Str(required=True)
class PlainCategorySchema(Schema):
id = fields.Str(dump_only=True)
name = fields.Str()
class ProductSchema(PlainProductSchema):
store_id = fields.Str(required=True, load_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
categories = fields.List(fields.Nested(PlainCategorySchema()), dump_only=True)
class StoreSchema(PlainStoreSchema):
products = fields.List(fields.Nested(PlainProductSchema(), dump_only=True))
categories = fields.List(fields.Nested(PlainCategorySchema()), dump_only=True)
class CategorySchema(PlainCategorySchema):
store_id = fields.Str(load_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
products = fields.List(fields.Nested(PlainProductSchema()), dump_only=True)
class CategoryAndProductSchema(Schema):
message = fields.Str()
product = fields.Nested(ProductSchema)
category = fields.Nested(CategorySchema)
class UserSchema(Schema):
id = fields.Str(dump_only=True)
username = fields.Str(required=True)
password = fields.Str(required=True, load_only=True)
class UserRegisterSchema(UserSchema):
email = fields.Email(required=True)