ShopBot/utils/database/model.py

49 lines
1.1 KiB
Python
Raw Normal View History

2022-06-04 22:02:51 +03:00
from peewee import (Model, BigIntegerField, TextField, BlobField,
IntegerField, CharField, FloatField, ForeignKeyField)
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):
pass
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])