-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
56 lines (45 loc) · 2.43 KB
/
models.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 tortoise import fields, Model
from pydantic import BaseModel
from tortoise.contrib.pydantic import pydantic_model_creator
from datetime import datetime
class User(Model):
id = fields.IntField(pk=True, index=True)
username = fields.CharField(max_length=20, null=False, unique=True)
email = fields.CharField(max_length=200, null=False, unique=True)
password = fields.CharField(max_length=100, null=False)
is_verified = fields.BooleanField(default=False)
join_data = fields.DatetimeField(default=datetime.utcnow)
class Business(Model):
id = fields.IntField(pk=True, index=True)
business_name = fields.CharField(max_length=20, null=False, unique=True)
city = fields.CharField(max_length=100, null=False, default="Unspecified")
region = fields.CharField(
max_length=100, null=False, default="Unspecified")
business_description = fields.TextField(null=True)
logo = fields.CharField(max_length=200, null=False, default="default.jpg")
owner = fields.ForeignKeyField('models.User', related_name='business')
class Product(Model):
id = fields.IntField(pk=True, index=True)
name = fields.CharField(max_length=100, null=False, index=True)
category = fields.CharField(max_length=20, index=True)
original_price = fields.DecimalField(max_digits=12, decimal_places=2)
new_price = fields.DecimalField(max_digits=12, decimal_places=2)
percentage_discount = fields.IntField()
offer_expiration_date = fields.DateField(default=datetime.utcnow)
product_image = fields.CharField(
max_length=200, null=False, default="productDefault.jpg")
date_published = fields.DatetimeField(default=datetime.utcnow)
business = fields.ForeignKeyField(
'models.Business', related_name='products')
user_pydantic = pydantic_model_creator(
User, name="User", exclude=("is_verified",))
user_pydanticIn = pydantic_model_creator(
User, name="UserIn", exclude_readonly=True, exclude=("is_verified", 'join_date'))
user_pydanticOut = pydantic_model_creator(
User, name="UserOut", exclude=("password", ))
business_pydantic = pydantic_model_creator(Business, name="Business")
business_pydanticIn = pydantic_model_creator(
Business, name="Business", exclude_readonly=True)
product_pydantic = pydantic_model_creator(Product, name="Product")
product_pydanticIn = pydantic_model_creator(Product, name="ProductIn",
exclude=("percentage_discount", "id"))