class ReplyLike(Model): """ ReplyLike Model for storing reply like related details """ # Details id = Column(db.Integer, primary_key=True) on_reply = Column(db.Integer, db.ForeignKey("reply.id")) owner_id = Column(db.Integer, db.ForeignKey("user.id")) liked_on = Column(db.DateTime, default=datetime.utcnow) def __repr__(self): return f"<ReplyLike on Reply '{self.on_comment}'>"
class PostLike(Model): """ PostLike Model for storing post like related details """ # Details id = Column(db.Integer, primary_key=True) on_post = Column(db.Integer, db.ForeignKey("post.id")) owner_id = Column(db.Integer, db.ForeignKey("user.id")) liked_on = Column(db.DateTime, default=datetime.utcnow) def __repr__(self): return f"<PostLike {self.id} on Post '{self.on_post}'>"
class Post(Model): """ Post Model for storing post related details """ # Basic details id = Column(db.Integer, primary_key=True) public_id = Column(db.String(15)) owner_id = Column(db.Integer, db.ForeignKey("user.id")) creator_public_id = Column(db.String(15)) # Post content and details content = Column(db.Text) image_file = Column(db.String(40), default=None, nullable=True) status = Column(db.String(10)) created = Column(db.DateTime, default=datetime.utcnow) edited = Column(db.Boolean, default=False) likes = db.relationship("PostLike", backref="post", cascade="all, delete-orphan") comments = db.relationship("Comment", backref="post", cascade="all, delete-orphan") def __repr__(self): return f"<Post '{self.id}'>"
class Notification(Model): id = Column(db.Integer, primary_key=True) owner_id = Column(db.Integer, db.ForeignKey("user.id")) # Example actions: 'liked', 'replied', 'commented', etc. action = Column(db.String(10)) timestamp = Column(db.DateTime) read = Column(db.Boolean, default=False) # Object names: post, comment, reply ... object_name = Column(db.String(20)) object_public_id = Column(db.String(15)) def is_read(self, read): self.read = True
class Notification(Model): id = Column(db.Integer, primary_key=True) # The user that committed the action, takes public_id. actor = Column(db.String(15)) # Target owner is the user receiving the notification. target_owner = Column(db.Integer, db.ForeignKey("user.id")) # Example actions: 'liked', 'replied', 'commented', etc. action = Column(db.String(10)) timestamp = Column(db.DateTime) read = Column(db.Boolean, default=False) # Object type: post, comment, reply ... object_type = Column(db.String(20)) object_public_id = Column(db.String(15)) def is_read(self, read): self.read = True
class Reply(Model): """ Reply Model for storing reply related details """ # Basic details id = Column(db.Integer, primary_key=True) public_id = Column(db.String(15)) creator_public_id = Column(db.String(15)) on_comment = Column(db.Integer, db.ForeignKey("comment.id")) # Reply content and details content = Column(db.Text) image_file = Column(db.String(40), default=None, nullable=True) created = Column(db.DateTime, default=datetime.utcnow) edited = Column(db.Boolean, default=False) likes = db.relationship("ReplyLike", backref="reply", cascade="all, delete-orphan") def __repr__(self): return f"<Reply '{self.id}'>"
from datetime import datetime from zimmerman.main import db, ma, bcrypt # Alias common SQLAlchemy names Column = db.Column Model = db.Model roles_users = db.Table( "roles_users", Column("user_id", db.Integer, db.ForeignKey("user.id")), Column("role_id", db.Integer, db.ForeignKey("role.id")), ) class User(Model): """ User Model for storing user related details """ # Basic details id = Column(db.Integer, primary_key=True) public_id = Column(db.String(15), unique=True) email = Column(db.String(255), unique=True, nullable=False) username = Column(db.String(15), unique=True) full_name = Column(db.String(50), nullable=True) password_hash = Column(db.String(255)) bio = Column(db.String(150), nullable=True) # Media profile_picture = Column(db.String(40), nullable=True) background_cover = Column(db.String(40), nullable=True)