52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from barker.models.modifier_category_product import ModifierCategoryProduct
|
|
from sqlalchemy import Boolean, Integer, Unicode, text
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from ..db.base_class import reg
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from .modifier import Modifier
|
|
from .product import Product
|
|
|
|
|
|
@reg.mapped_as_dataclass(unsafe_hash=True)
|
|
class ModifierCategory:
|
|
__tablename__ = "modifier_categories"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4
|
|
)
|
|
name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True)
|
|
minimum: Mapped[int] = mapped_column("minimum", Integer, nullable=False)
|
|
maximum: Mapped[Optional[int]] = mapped_column("maximum", Integer, nullable=True)
|
|
is_active: Mapped[bool] = mapped_column("is_active", Boolean, nullable=False)
|
|
sort_order: Mapped[int] = mapped_column("sort_order", Integer, nullable=False)
|
|
|
|
products: Mapped[List["Product"]] = relationship(
|
|
secondary=ModifierCategoryProduct.__table__, # type: ignore[attr-defined]
|
|
back_populates="modifier_categories",
|
|
)
|
|
modifiers: Mapped[List["Modifier"]] = relationship(back_populates="modifier_category")
|
|
|
|
def __init__(
|
|
self,
|
|
name=None,
|
|
minimum=None,
|
|
maximum=None,
|
|
is_active=True,
|
|
sort_order=0,
|
|
id_=None,
|
|
):
|
|
self.id = id_
|
|
self.name = name
|
|
self.minimum = minimum
|
|
self.maximum = maximum
|
|
self.is_active = is_active
|
|
self.sort_order = sort_order
|