30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from uuid import uuid4
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class Review(Base):
|
|
__tablename__ = "reviews"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid4()))
|
|
product_id = Column(String(36), ForeignKey("products.id", ondelete="CASCADE"), nullable=False)
|
|
user_id = Column(String(36), ForeignKey("users.id"), nullable=False)
|
|
rating = Column(Integer, nullable=False) # 1-5 rating
|
|
title = Column(String(255), nullable=True)
|
|
comment = Column(Text, nullable=True)
|
|
is_verified_purchase = Column(Boolean, default=False)
|
|
is_approved = Column(Boolean, default=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
product = relationship("Product", back_populates="reviews")
|
|
user = relationship("User", back_populates="reviews")
|
|
|
|
def __repr__(self):
|
|
return f"<Review {self.id} by User {self.user_id} for Product {self.product_id}>"
|