41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Boolean, Column, Unicode
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from .meta import Base
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
# if the target of the relationship is in another module
|
|
# that cannot normally be imported at runtime
|
|
from .product import Product
|
|
|
|
|
|
class ProductGroup(Base):
|
|
__tablename__ = "product_groups"
|
|
|
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name: str = Column("name", Unicode(255), unique=True)
|
|
is_fixture: bool = Column("is_fixture", Boolean, nullable=False)
|
|
|
|
products: List["Product"] = relationship("Product", back_populates="product_group")
|
|
|
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None, is_fixture: Optional[bool] = False) -> None:
|
|
self.name = name
|
|
if id_ is not None:
|
|
self.id = id_
|
|
if is_fixture is not None:
|
|
self.is_fixture = is_fixture
|
|
|
|
@classmethod
|
|
def menu_item(cls) -> uuid.UUID:
|
|
return uuid.UUID("dad46805-f577-4e5b-8073-9b788e0173fc")
|
|
|
|
@classmethod
|
|
def semi(cls) -> uuid.UUID:
|
|
return uuid.UUID("e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1")
|