63 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
 | 
						|
from sqlalchemy.orm import relationship
 | 
						|
 | 
						|
from models import BaseModel
 | 
						|
 | 
						|
 | 
						|
class Client(BaseModel):
 | 
						|
    __tablename__ = 'clients'
 | 
						|
    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
						|
    name = Column(String, nullable=False, unique=True, comment='Название клиента')
 | 
						|
 | 
						|
    # TODO replace with additional model
 | 
						|
    company_name = Column(String,
 | 
						|
                          nullable=False,
 | 
						|
                          server_default='',
 | 
						|
                          comment='Название компании')
 | 
						|
 | 
						|
    created_at = Column(DateTime, nullable=False, comment='Дата создания')
 | 
						|
 | 
						|
    products = relationship('Product', back_populates='client')
 | 
						|
    details = relationship('ClientDetails', 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')
 | 
						|
    # users = relationship('ClientUser', back_populates='client', cascade='all, delete')
 | 
						|
 | 
						|
 | 
						|
class ClientDetails(BaseModel):
 | 
						|
    __tablename__ = 'client_details'
 | 
						|
 | 
						|
    id = Column(Integer, autoincrement=True, primary_key=True, index=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)
 | 
						|
 | 
						|
    telegram = Column(String)
 | 
						|
    phone_number = Column(String)
 | 
						|
    inn = Column(String)
 | 
						|
    email = Column(String)
 | 
						|
 | 
						|
    last_modified_at = Column(DateTime, 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()
 | 
						|
#
 |