wahnsinn vibe
This commit is contained in:
34
backend/apps/orders/models.py
Normal file
34
backend/apps/orders/models.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import JSON, DateTime, ForeignKey, Integer, Numeric, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from core.db import Base
|
||||
|
||||
|
||||
class Order(Base):
|
||||
__tablename__ = "orders"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="paid")
|
||||
total: Mapped[float] = mapped_column(Numeric(10, 2))
|
||||
currency: Mapped[str] = mapped_column(String(3), default="EUR")
|
||||
address: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
payment: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
items: Mapped[list[dict]] = mapped_column(JSON, default=list)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
status_history: Mapped[list["OrderStatusHistory"]] = relationship(
|
||||
"OrderStatusHistory", cascade="all, delete-orphan", lazy="joined"
|
||||
)
|
||||
|
||||
|
||||
class OrderStatusHistory(Base):
|
||||
__tablename__ = "order_status_history"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
order_id: Mapped[int] = mapped_column(ForeignKey("orders.id", ondelete="CASCADE"))
|
||||
status: Mapped[str] = mapped_column(String(32))
|
||||
note: Mapped[str] = mapped_column(String(500), default="")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in New Issue
Block a user