ShopBot/utils/database/model.py

50 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-06-04 22:02:51 +03:00
from peewee import (Model, BigIntegerField, TextField, BlobField,
2022-06-05 15:02:41 +03:00
IntegerField, CharField, FloatField, BooleanField)
2022-06-04 22:02:51 +03:00
from load import db
class BaseModel(Model):
2022-06-05 15:02:41 +03:00
"""Base model. Abstract Class"""
2022-06-04 22:02:51 +03:00
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):
2022-06-05 15:02:41 +03:00
active = BooleanField(default=False)
2022-06-04 22:02:51 +03:00
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()
2022-06-05 15:02:41 +03:00
2022-06-04 22:02:51 +03:00
db.create_tables([Cart, Catalog, Operator, Admin, User, UserInfo])