Beispiel #1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    category = db.Column(db.Enum(categoryEnum), nullable=False)
    status = db.Column(db.Enum(statusEnum), default=statusEnum.OPEN)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    volunteer = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False, default=0)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #2
0
class ChatChannel(db.Model):
    __tablename__ = "chatchannel"

    id = db.Column(db.Integer, primary_key=True)
    user1_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)  # always lower than user2_id
    user2_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    user1_status = db.Column(db.Enum(channelStatusEnum), default=channelStatusEnum.READ)
    user2_status = db.Column(db.Enum(channelStatusEnum), default=channelStatusEnum.READ)

    user_1 = db.relationship("User", backref=backref("usr_1", uselist=False), foreign_keys=[user1_id])
    user_2 = db.relationship("User", backref=backref("usr_2", uselist=False), foreign_keys=[user2_id])

    def __repr__(self):
        return f"ChatChannel('{self.user1_id}', '{self.user2_id}', '{self.user_1.username}', '{self.user_2.username}', '{self.last_updated}')"
Beispiel #3
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    recipient = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    notifier = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id', ondelete='CASCADE'), nullable=False)
    notification_message = db.Column(db.Text, nullable=False)
    is_read = db.Column(db.Boolean, nullable=False, default=0)
    type = db.Column(db.Enum(notificationTypeEnum), nullable=False)
Beispiel #4
0
class ChatMessages(db.Model):
    __tablename__ = "chatmessages"

    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    message_content = db.Column(db.Text, nullable=False)
    message_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    message_status = db.Column(db.Enum(messageStatusEnum), default=messageStatusEnum.SENT)

    channel_id = db.Column(db.Integer, db.ForeignKey('chatchannel.id', ondelete='CASCADE'), nullable=False)
    sender = db.relationship("User", backref=backref("usr_snd", uselist=False), foreign_keys=[sender_id])

    def __repr__(self):
        return f"ChatMessages('{self.sender}', '{self.message_content}', '{self.message_sent}', '{self.message_time}, {self.channel_id}')"