Files
classifieds/app/models/review.py
T
2026-06-18 09:29:33 -04:00

35 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Seller reviews — left by buyers after a listing is marked sold."""
from datetime import datetime
from app.extensions import db
class Review(db.Model):
__tablename__ = "reviews"
id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
primary_key=True, autoincrement=True)
listing_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
db.ForeignKey("listings.id"), nullable=False, index=True)
author_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
db.ForeignKey("users.id"), nullable=False, index=True)
seller_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"),
db.ForeignKey("users.id"), nullable=False, index=True)
rating = db.Column(db.SmallInteger, nullable=False) # 15
body = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
listing = db.relationship("Listing",
backref=db.backref("reviews", lazy="dynamic"))
author = db.relationship("User", foreign_keys=[author_id],
backref=db.backref("reviews_written", lazy="dynamic"))
seller = db.relationship("User", foreign_keys=[seller_id],
backref=db.backref("reviews_received", lazy="dynamic"))
__table_args__ = (
db.UniqueConstraint("listing_id", "author_id", name="uq_review_listing_author"),
db.CheckConstraint("rating BETWEEN 1 AND 5", name="ck_review_rating"),
)
def __repr__(self):
return f"<Review L{self.listing_id} by u{self.author_id} {self.rating}*>"