06/18 Phase 7
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""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) # 1–5
|
||||
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}*>"
|
||||
Reference in New Issue
Block a user