44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from models.base import BaseModel
|
|
from models.mixins import IdMixin, SoftDeleteMixin
|
|
|
|
if TYPE_CHECKING:
|
|
from models import Attribute
|
|
|
|
|
|
class AttributeSelect(BaseModel, IdMixin, SoftDeleteMixin):
|
|
__tablename__ = "attribute_selects"
|
|
|
|
name: Mapped[str] = mapped_column()
|
|
is_built_in: Mapped[bool] = mapped_column(
|
|
default=False,
|
|
comment="Если встроенный select, то запрещено редактировать пользователю",
|
|
)
|
|
|
|
options: Mapped[list["AttributeOption"]] = relationship(
|
|
back_populates="select",
|
|
lazy="noload",
|
|
)
|
|
|
|
attributes: Mapped[list["Attribute"]] = relationship(
|
|
back_populates="select",
|
|
lazy="noload",
|
|
)
|
|
|
|
|
|
class AttributeOption(BaseModel, IdMixin, SoftDeleteMixin):
|
|
__tablename__ = "attribute_options"
|
|
|
|
name: Mapped[str] = mapped_column()
|
|
lexorank: Mapped[str] = mapped_column(comment="Ранг опции")
|
|
|
|
select_id: Mapped[int] = mapped_column(ForeignKey("attribute_selects.id"))
|
|
select: Mapped[AttributeSelect] = relationship(
|
|
back_populates="options",
|
|
lazy="noload",
|
|
)
|