Example #1
0
class Comment(Model):
    """ Comment Model for storing comment 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"), nullable=False)
    creator_public_id = Column(db.String(15))
    on_post = Column(db.Integer, db.ForeignKey("post.id"))

    # Comment 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 = relationship("CommentLike",
                         backref="comment",
                         cascade="all, delete-orphan",
                         lazy=True)
    replies = relationship("Reply",
                           backref="comment",
                           cascade="all, delete-orphan",
                           lazy=True)

    def __repr__(self):
        return f"<Comment '{self.id}'>"
Example #2
0
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}'>"
Example #3
0
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}'>"
Example #4
0
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))
    owner_id = Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    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 = relationship("ReplyLike",
                         backref="reply",
                         cascade="all, delete-orphan")

    def __repr__(self):
        return "<Reply {self.id}>"
Example #5
0
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, default=datetime.utcnow)
    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
Example #6
0
from zimmerman import db, bcrypt

# Alias common SQLAlchemy names
Column = db.Column
Model = db.Model
relationship = db.relationship

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)
    password_hash = Column(db.String(255))

    private = Column(db.Boolean, default=False)

    # Optional
    full_name = Column(db.String(50), nullable=True)
    bio = Column(db.String(150), nullable=True)
    orientation = Column(db.String(30), nullable=True)