60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from sqlalchemy import JSON, Column, ForeignKey, Integer, String, create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import relationship
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
class Car(Base):
|
|
__tablename__ = 'cars'
|
|
|
|
ID = Column(Integer, primary_key=True)
|
|
vendor = Column(String)
|
|
model = Column(String)
|
|
year = Column(String)
|
|
power = Column(String)
|
|
modification = Column(String)
|
|
|
|
categories = relationship("Category", back_populates="car")
|
|
|
|
|
|
class Category(Base):
|
|
__tablename__ = 'categories'
|
|
|
|
ID = Column(Integer, primary_key=True)
|
|
ID_car = Column(Integer, ForeignKey('cars.ID'))
|
|
num_category = Column(String)
|
|
name = Column(String)
|
|
url = Column(String)
|
|
car = relationship("Car", back_populates="categories")
|
|
products = relationship("Product", back_populates="category")
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = 'product'
|
|
|
|
ID = Column(Integer, primary_key=True)
|
|
ID_category = Column(Integer, ForeignKey('categories.ID'))
|
|
code = Column(String)
|
|
img_src = Column(String)
|
|
description = Column(String)
|
|
info = Column(String)
|
|
product_link = Column(String)
|
|
|
|
category = relationship("Category", back_populates="products")
|
|
articls = relationship("Articl", back_populates="product")
|
|
|
|
|
|
class Articl(Base):
|
|
__tablename__ = 'articl'
|
|
|
|
ID = Column(Integer, primary_key=True)
|
|
code = Column(String, ForeignKey('product.code'))
|
|
json_info = Column(JSON)
|
|
|
|
product = relationship("Product", back_populates="articls")
|
|
|
|
|
|
engine = create_engine('sqlite:///cars_database.db')
|
|
Base.metadata.create_all(engine)
|