-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa8c483
commit 02e0c72
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |