Add Order model
This commit is contained in:
parent
8f6cedbb49
commit
2e9bb7acec
22
models/order.py
Normal file
22
models/order.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey, Numeric
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from core.database import Base
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class Order(Base):
|
||||||
|
__tablename__ = "orders"
|
||||||
|
|
||||||
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||||
|
order_number = Column(String, unique=True, nullable=False, index=True)
|
||||||
|
customer_id = Column(String, ForeignKey("users.id"), nullable=False)
|
||||||
|
total_amount = Column(Numeric(10, 2), nullable=False)
|
||||||
|
status = Column(String, nullable=False, default="pending")
|
||||||
|
shipping_address = Column(String, nullable=False)
|
||||||
|
payment_status = Column(String, nullable=False, default="unpaid")
|
||||||
|
|
||||||
|
created_at = Column(DateTime, default=func.now())
|
||||||
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||||
|
|
||||||
|
customer = relationship("User", back_populates="orders")
|
||||||
|
order_items = relationship("OrderItem", back_populates="order", cascade="all, delete-orphan")
|
Loading…
x
Reference in New Issue
Block a user