Skip to content

Commit

Permalink
add review
Browse files Browse the repository at this point in the history
  • Loading branch information
vivitruong committed Mar 7, 2024
1 parent fa8c483 commit 02e0c72
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/models/review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from .db import db


class Review(db.Model):
__tablename__ = 'reviews'

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(
db.Integer, db.ForeignKey('users.id'), nullable=False)
product_id = db.Column(
db.Integer, db.ForeignKey('products.id'), nullable=False)
content = db.Column(db.String(1000), nullable=False)
stars = db.Column(db.Integer, nullable=False)
created_at = db.Column(db.DateTime(timezone=True),
nullable=False, server_default=db.func.now())
updated_at = db.Column(db.DateTime(timezone=True))

user = db.relationship(
'User', back_populates='reviews', foreign_keys=[user_id])
product = db.relationship(
'Product', back_populates='reviews', foreign_keys=[product_id])

def to_dict(self):
return {
'id': self.id,
'user_id': self.user_id,
'product_id': self.product_id,
'content': self.content,
'stars': self.stars,
'created_at': self.created_at
}

def to_dict_stars(self):
return {
'stars' : int(self.stars)
}

0 comments on commit 02e0c72

Please sign in to comment.