Exemplo n.º 1
0
class Like(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    __table_args__ = (UniqueConstraint('post_id',
                                       'user_id',
                                       name='post_user_like_unique'), )
Exemplo n.º 2
0
class PendingApproval(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    prof_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    student_id = db.Column(db.Integer,
                           db.ForeignKey('user.id'),
                           nullable=False)
    __table_args__ = (
        # Make sure a user can not follow himself.
        CheckConstraint(prof_id != student_id, name='check_student_not_prof'),
        UniqueConstraint('prof_id', 'student_id', name='student_prof_unique'),
    )
Exemplo n.º 3
0
class Subscription(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    follower = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    followee = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    # followee_type can be user or lab
    followee_type = db.Column(db.String(10), nullable=False, default='user')

    __table_args__ = (UniqueConstraint('follower',
                                       'followee',
                                       'followee_type',
                                       name='follower_followee_unique'), )
Exemplo n.º 4
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    file = db.Column(db.String(20), nullable=True)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    likes = db.relationship('Like', backref='post', lazy=True)
    like_count = db.Column(db.Integer, default=0)

    # one of author_id or lab_id must be set TODO: add constraint
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    lab_id = db.Column(db.Integer, db.ForeignKey('lab.id'), nullable=True)

    # author_type can be user or lab
    author_type = db.Column(db.String(10), nullable=False, default='user')

    def __repr__(self):
        return f"Post('{self.title}','{self.created_at}','{self.author_id}')"
Exemplo n.º 5
0
from iiit_research import db, login_manager, app


@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


# http://flask-sqlalchemy.pocoo.org/2.3/models/#many-to-many-relationships
# A mapping between user and area of interests
UserInterests = db.Table(
    'user_interests',
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.id'),
              primary_key=True),
    db.Column('interest_id',
              db.Integer,
              db.ForeignKey('interest.id'),
              primary_key=True))

# A mapping between lab and its members
LabMembers = db.Table(
    'lab_members',
    db.Column('lab_id', db.Integer, db.ForeignKey('lab.id'), primary_key=True),
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('user.id'),
              primary_key=True))