feat: cards, attributes and modules
This commit is contained in:
@@ -1,70 +1,59 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import ResidualPallet, ResidualBox
|
||||
from models import ResidualPallet, ResidualBox, Product, BarcodeTemplate, User
|
||||
|
||||
|
||||
class Client(BaseModel):
|
||||
__tablename__ = 'clients'
|
||||
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False, unique=True, comment='Название клиента')
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False, unique=True, comment='Название клиента')
|
||||
|
||||
# TODO replace with additional model
|
||||
company_name = Column(String,
|
||||
nullable=False,
|
||||
server_default='',
|
||||
comment='Название компании')
|
||||
company_name: Mapped[str] = mapped_column(
|
||||
nullable=False,
|
||||
server_default='',
|
||||
comment='Название компании',
|
||||
)
|
||||
|
||||
created_at = Column(DateTime, nullable=False, comment='Дата создания')
|
||||
created_at: Mapped[datetime] = mapped_column(nullable=False, comment='Дата создания')
|
||||
|
||||
products = relationship('Product', back_populates='client')
|
||||
details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete',
|
||||
lazy='joined')
|
||||
products: Mapped[list['Product']] = relationship('Product', back_populates='client')
|
||||
details: Mapped['ClientDetails'] = relationship(
|
||||
uselist=False,
|
||||
back_populates='client',
|
||||
cascade='all, delete',
|
||||
lazy='joined',
|
||||
)
|
||||
|
||||
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
|
||||
barcode_template = relationship('BarcodeTemplate', lazy='selectin')
|
||||
barcode_template_id: Mapped[int] = mapped_column(ForeignKey('barcode_templates.id'), nullable=True)
|
||||
barcode_template: Mapped['BarcodeTemplate'] = relationship('BarcodeTemplate', lazy='selectin')
|
||||
|
||||
comment: Mapped[Optional[str]] = mapped_column(nullable=True, server_default=None, comment='Комментарий')
|
||||
|
||||
pallets: Mapped[list["ResidualPallet"]] = relationship(back_populates='client', lazy='selectin')
|
||||
boxes: Mapped[list["ResidualBox"]] = relationship(back_populates='client', lazy='selectin')
|
||||
pallets: Mapped[list['ResidualPallet']] = relationship(back_populates='client', lazy='selectin')
|
||||
boxes: Mapped[list['ResidualBox']] = relationship(back_populates='client', lazy='selectin')
|
||||
|
||||
|
||||
class ClientDetails(BaseModel):
|
||||
__tablename__ = 'client_details'
|
||||
|
||||
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
||||
client_id = Column(Integer, ForeignKey('clients.id'), unique=True, nullable=False, comment='ID клиента')
|
||||
client = relationship('Client', back_populates='details', cascade='all, delete', uselist=False)
|
||||
client_id: Mapped[int] = mapped_column(ForeignKey('clients.id'), unique=True, nullable=False, comment='ID клиента')
|
||||
client: Mapped[Client] = relationship('Client', back_populates='details', cascade='all, delete', uselist=False)
|
||||
|
||||
telegram = Column(String)
|
||||
phone_number = Column(String)
|
||||
inn = Column(String)
|
||||
email = Column(String)
|
||||
telegram: Mapped[Optional[str]] = mapped_column()
|
||||
phone_number: Mapped[Optional[str]] = mapped_column()
|
||||
inn: Mapped[Optional[str]] = mapped_column()
|
||||
email: Mapped[Optional[str]] = mapped_column()
|
||||
|
||||
last_modified_at = Column(DateTime, nullable=False)
|
||||
last_modified_at: Mapped[datetime] = mapped_column(nullable=False)
|
||||
|
||||
modified_by_user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||
modified_by_user = relationship('User')
|
||||
|
||||
# class ClientContact(BaseModel):
|
||||
# __tablename__ = 'client_contact'
|
||||
# id: Mapped[int] = mapped_column(primary_key=True)
|
||||
#
|
||||
# client_id: Mapped[int] = mapped_column(ForeignKey('clients.id'))
|
||||
# client: Mapped["Client"] = relationship('Client', back_populates='users')
|
||||
#
|
||||
# first_name: Mapped[str] = mapped_column()
|
||||
# last_name: Mapped[str] = mapped_column()
|
||||
#
|
||||
# telegram: Mapped[str] = mapped_column()
|
||||
# phone_number: Mapped[str] = mapped_column()
|
||||
# email: Mapped[str] = mapped_column()
|
||||
# inn: Mapped[str] = mapped_column()
|
||||
#
|
||||
modified_by_user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), nullable=False)
|
||||
modified_by_user: Mapped['User'] = relationship('User')
|
||||
|
||||
Reference in New Issue
Block a user