wahnsinn vibe
This commit is contained in:
39
backend/apps/catalog/models.py
Normal file
39
backend/apps/catalog/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, Numeric, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from core.db import Base
|
||||
|
||||
|
||||
class Category(Base):
|
||||
__tablename__ = "categories"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
slug: Mapped[str] = mapped_column(String(128), unique=True, index=True)
|
||||
name: Mapped[dict] = mapped_column(JSON, default=dict) # {'de': '...', 'en': '...'}
|
||||
parent_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("categories.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
sku: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
name: Mapped[dict] = mapped_column(JSON, default=dict) # i18n
|
||||
description: Mapped[dict] = mapped_column(JSON, default=dict) # i18n
|
||||
price: Mapped[float] = mapped_column(Numeric(10, 2))
|
||||
currency: Mapped[str] = mapped_column(String(3), default="EUR")
|
||||
stock: Mapped[int] = mapped_column(Integer, default=0)
|
||||
active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
image_url: Mapped[str] = mapped_column(String(500), default="")
|
||||
category_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("categories.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
attributes: Mapped[dict] = mapped_column(JSON, default=dict) # color, size, ...
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
category: Mapped[Category | None] = relationship("Category", lazy="joined")
|
||||
Reference in New Issue
Block a user