fix: default option in attributes
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
@ -34,7 +33,6 @@ class AttributeSelect(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
class AttributeOption(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
__tablename__ = "attribute_options"
|
||||
|
||||
value: Mapped[dict[str, any]] = mapped_column(JSONB)
|
||||
label: Mapped[str] = mapped_column()
|
||||
|
||||
select_id: Mapped[int] = mapped_column(ForeignKey("attribute_selects.id"))
|
||||
@ -42,5 +40,3 @@ class AttributeOption(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
back_populates="options",
|
||||
lazy="noload",
|
||||
)
|
||||
|
||||
__table_args__ = (UniqueConstraint("value", "select_id", name="_value_select_uc"),)
|
||||
|
||||
@ -8,7 +8,7 @@ from models.base import BaseModel
|
||||
from models.mixins import IdMixin, SoftDeleteMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Module, Deal, AttributeSelect
|
||||
from models import Module, Deal, AttributeSelect, AttributeOption
|
||||
|
||||
module_attribute = Table(
|
||||
"module_attribute",
|
||||
@ -39,7 +39,15 @@ class Attribute(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
comment="Применять ли изменения атрибута карточки ко всем карточкам в группе",
|
||||
)
|
||||
is_nullable: Mapped[bool] = mapped_column(default=False)
|
||||
|
||||
default_value: Mapped[Optional[dict[str, any]]] = mapped_column(JSONB)
|
||||
default_option_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey("attribute_options.id")
|
||||
)
|
||||
default_option: Mapped[Optional["AttributeOption"]] = relationship(
|
||||
backref="attributes", lazy="joined"
|
||||
)
|
||||
|
||||
description: Mapped[str] = mapped_column(default="")
|
||||
|
||||
is_built_in: Mapped[bool] = mapped_column(default=False)
|
||||
|
||||
Reference in New Issue
Block a user