from db import db


class PostModel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text(500), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'))

    @classmethod
    def get_by_user_id(cls, user_id):
        return cls.query.filter_by(user_id=user_id).all()

    @classmethod
    def get_by_id(cls, post_id):
        return cls.query.get(post_id)

    @classmethod
    def get_all(cls):
        return cls.query.all()
