feat: deal product services

This commit is contained in:
2024-05-13 07:46:13 +03:00
parent e9aec10feb
commit be650aca74
10 changed files with 136 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
from sqlalchemy import Column, Integer, String, ForeignKey, Double
from sqlalchemy import Column, Integer, String, ForeignKey, Double, asc
from sqlalchemy.orm import relationship, mapped_column, Mapped
import enums.service
from models import BaseModel
@@ -10,9 +11,26 @@ class Service(BaseModel):
name = Column(String, nullable=False, comment='Название услуги')
category_id = Column(Integer, ForeignKey('service_categories.id'), nullable=False, comment='ID категории услуги')
category = relationship('ServiceCategory')
category = relationship('ServiceCategory', lazy='joined')
price = Column(Double, nullable=False, comment='Стоимость услуги')
service_type = Column(Integer,
server_default=f'{enums.service.ServiceType.DEAL_SERVICE}',
nullable=False,
comment='Тип услуги')
price_ranges = relationship('ServicePriceRange', back_populates='service', lazy='selectin',
order_by="asc(ServicePriceRange.from_quantity)")
class ServicePriceRange(BaseModel):
__tablename__ = 'service_price_ranges'
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
service_id = Column(Integer, ForeignKey('services.id'), nullable=False, comment='ID услуги')
service = relationship('Service', back_populates='price_ranges')
from_quantity = Column(Integer, nullable=False, comment='От количества')
to_quantity = Column(Integer, nullable=False, comment='До количества')
price = Column(Double, nullable=False, comment='Цена')
class ServiceCategory(BaseModel):