ShopBot/utils/database/model.py
2022-06-05 15:02:41 +03:00

50 lines
1.1 KiB
Python

from peewee import (Model, BigIntegerField, TextField, BlobField,
IntegerField, CharField, FloatField, BooleanField)
from load import db
class BaseModel(Model):
"""Base model. Abstract Class"""
class Meta:
database = db
class User(BaseModel):
user_id = BigIntegerField(null=False, unique=True)
first_name = CharField(null=False, max_length=64)
last_name = CharField(null=True, max_length=64)
username = CharField(null=True, max_length=32)
class Admin(User):
pass
class Operator(User):
active = BooleanField(default=False)
class Catalog(BaseModel):
name = TextField()
description = TextField()
image = BlobField()
price = FloatField()
class Cart(BaseModel):
user_id = BigIntegerField()
product_id = IntegerField()
count = IntegerField(default=1)
class UserInfo(BaseModel):
user_id = BigIntegerField(null=False, unique=True)
first_name = TextField()
last_name = TextField()
phone_number = CharField(15)
address = TextField()
db.create_tables([Cart, Catalog, Operator, Admin, User, UserInfo])