Products_xlsx/models.py

115 lines
4.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import datetime
from dotenv import load_dotenv
from peewee import *
load_dotenv()
DATABASE_L = os.getenv("DATABASE_L")
DB_HOST_L = os.getenv("DB_HOST_L")
USERS_L = os.getenv("USERS_L")
PASSW_L = os.getenv("PASSW_L")
db = MySQLDatabase(
database=DATABASE_L, user=USERS_L, password=PASSW_L, host=DB_HOST_L, port=3306, autocommit=True
)
class ProductParameter(Model):
id = AutoField(primary_key=True)
parameter_name = CharField(max_length=50, unique=True) # Название параметра
class Meta:
database = db
table_name = "product_parameters"
# Модель для хранения информации о категориях товаров
class ProductCategory(Model):
id = AutoField(primary_key=True)
category_name = CharField(max_length=50) # Название категории
id_1c_d = CharField(max_length=50, unique=True)
is_active = BooleanField(default=1, null=True)
class Meta:
database = db
table_name = "product_categories"
# Модель для хранения информации о товарах
class Product(Model):
id = AutoField(primary_key=True)
id_1c = CharField(max_length=50, unique=True) # ID из 1C
vendor_code = CharField(max_length=50, null=True)
product_name = CharField(max_length=255, null=True) # Название товара
description = TextField(null=True) # Описание товара
price_rrc = FloatField(null=True) # Цена 1
price_drop = FloatField(null=True) # Цена 2
price_opt = FloatField(null=True) # Цена 3
price_large_opt = FloatField(null=True) # Цена 4
price_drop_pro = FloatField(null=True) # Цена 5
price_os_kripto_to = FloatField(null=True) # Цена 6
price_hot = FloatField(null=True) # Цена 6
price_rozetka = FloatField(null=True)
price_epicenter = FloatField(null=True)
price_allo = FloatField(null=True)
category = ForeignKeyField(ProductCategory, backref='products')
os_lugi = CharField(max_length=50, null=True) # ID площадки 1
prom_lugi = CharField(max_length=50, null=True) # ID площадки 2
prom_hot = CharField(max_length=50, null=True) # ID площадки 3
rozetka = CharField(max_length=50, null=True) # ID площадки 4
crm_id = CharField(max_length=50, null=True) # ID площадки 5
platform_6_id = CharField(max_length=50, null=True) # ID площадки 6
photo_url = TextField(null=True) # Ссылка на фото
url_to_shop = TextField(null=True)
weight = FloatField(null=True) # Вес
length = FloatField(null=True) # Длина
width = FloatField(null=True) # Ширина
height = FloatField(null=True) # Высота
quantity = IntegerField(null=True) # Количество
last_updated = DateTimeField(default=datetime.datetime.now)
sort = IntegerField(default=55, null=True)
class Meta:
database = db
table_name = "products_lugi"
# Модель для хранения значений параметров товаров
class ProductParameterValue(Model):
id = AutoField(primary_key=True)
product = ForeignKeyField(Product, backref='product_parameter_values')
parameter = ForeignKeyField(ProductParameter, backref='parameter_values')
value = CharField() # Значение параметра
class Meta:
database = db
table_name = "product_parameter_values"
# Модель для хранения информации об акциях
class ProductPromotion(Model):
id = AutoField(primary_key=True)
product_id = ForeignKeyField(Product, backref='product_promotions')
discount_rrc = IntegerField(null=True) # Скидка в процентах
discount_drop = IntegerField(null=True)
discount_drop_pro = IntegerField(null=True)
discount_opt = IntegerField(null=True)
discount_large_opt = IntegerField(null=True)
discount_hot = IntegerField(null=True)
discount_prom = IntegerField(null=True)
start_date = DateTimeField(null=True) # Дата начала акции
end_date = DateTimeField(null=True) # Дата окончания акции
last_updated = DateTimeField(default=datetime.datetime.now)
class Meta:
database = db
table_name = "product_promotion"
# Создание таблиц в базе данных
if __name__ == "__main__":
with db:
db.create_tables([Product, ProductParameter, ProductParameterValue, ProductPromotion, ProductCategory])