38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
"""
|
|
@model ProductReviewModel (Backend/app/models/ProductReviewModel.py)
|
|
@purpose Relational Product Review and normalized ProductReviewImage models for moderated customer feedback.
|
|
"""
|
|
from sqlalchemy import Column, String, Integer, Boolean, Text, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from app.models.db_base import Base
|
|
from app.models.audit_base import AuditBaseMixin
|
|
|
|
class ProductReview(Base, AuditBaseMixin):
|
|
__tablename__ = "product_reviews"
|
|
|
|
review_id = Column(String(36), primary_key=True, index=True)
|
|
product_id = Column(String(36), ForeignKey("products.product_id"), nullable=False, index=True)
|
|
user_id = Column(String(36), nullable=True, index=True)
|
|
author_name = Column(String(128), nullable=False)
|
|
author_email = Column(String(255), nullable=True)
|
|
rating = Column(Integer, nullable=False, default=5)
|
|
title = Column(String(255), nullable=False)
|
|
comment = Column(Text, nullable=False)
|
|
verified_purchase = Column(Boolean, default=True, nullable=False)
|
|
is_approved = Column(Boolean, default=True, nullable=False, index=True)
|
|
helpful_count = Column(Integer, default=0, nullable=False)
|
|
admin_reply = Column(Text, nullable=True)
|
|
|
|
images = relationship("ProductReviewImage", back_populates="review", cascade="all, delete-orphan")
|
|
|
|
class ProductReviewImage(Base, AuditBaseMixin):
|
|
__tablename__ = "product_review_images"
|
|
|
|
image_id = Column(String(36), primary_key=True, index=True)
|
|
review_id = Column(String(36), ForeignKey("product_reviews.review_id"), nullable=False, index=True)
|
|
image_url = Column(String(1000), nullable=False)
|
|
caption = Column(String(255), nullable=True)
|
|
display_order = Column(Integer, default=0, nullable=False)
|
|
is_approved = Column(Boolean, default=True, nullable=False, index=True)
|
|
|
|
review = relationship("ProductReview", back_populates="images")
|