22 lines
913 B
Python
22 lines
913 B
Python
from sqlalchemy import Column, String, Boolean, DateTime
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.core.database.db_session import Base
|
|
from app.models.BrandDeviceTypeModel import BrandDeviceType
|
|
|
|
class Brand(Base):
|
|
__tablename__ = "brands"
|
|
|
|
brand_id = Column(String(26), primary_key=True)
|
|
name = Column(String(100), unique=True, nullable=False)
|
|
slug = Column(String(100), unique=True, nullable=False)
|
|
logo_url = Column(String(500), nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
device_types_rel = relationship("BrandDeviceType", back_populates="brand", cascade="all, delete-orphan")
|
|
|
|
@property
|
|
def device_types(self):
|
|
return [dt.device_type for dt in self.device_types_rel]
|