class movies(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(40)) desc = db.Column(db.String(255), nullable=False, default=False) category = db.Column(db.String(40), nullable=False, default=False) rental = db.relationship('rental_info', backref='rental_info', uselist=False)
class User(db.Model): """Basic user model """ __tablename__ = "user_v2" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) tweets = db.relationship('Tweet', backref='tweet_user', lazy='dynamic') followed = db.relationship('User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id), backref=db.backref('follower', lazy='dynamic'), lazy='dynamic') active = db.Column(db.Boolean, default=False) def __init__(self, **kwargs): super(User, self).__init__(**kwargs) self.password = pwd_context.hash(self.password) def __repr__(self): return "<User %s>" % self.username def follow(self, user): if not self.is_following(user): self.followed.append(user) def unfollow(self, user): if self.is_following(user): self.followed.remove(user) def is_following(self, user): return self.followed.filter( followers.c.followed_id == user.id).count() > 0 def followed_tweet(self): followed = Tweet.query.join( followers, (followers.c.followed_id == Tweet.user_id)).filter( followers.c.followed_id == self.id) own = Tw.query.filter_by(user_id=self.id) return followed.union(own).order_by(Tweet.timestamp.desc())
class Survey(db.Model): __table__ = 'survey' id = db.Column(db.Integer, primary_key=True, index=True) description = db.Column(db.String(250), index=True) startdate = db.Column(db.DateTime) enddate = db.Column(db.DateTime) status = db.Column(db.Boolean, default=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) questions = db.relationship('Question', backref='questions', lazy='dynamic') response = db.Column(db.String(250), index=True) def __repr__(self): return "<Survey {}".format(self.description)
class User(db.Model): """Basic user model """ __tablename__ = ("user_v2") id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) active = db.Column(db.Boolean, default=True) list_of_rented_movies = db.relationship('rental_info', backref='renter') def __init__(self, **kwargs): super(User, self).__init__(**kwargs) self.password = pwd_context.hash(self.password) def __repr__(self): return "<User %s>" % self.username
class TokenBlocklist(db.Model): """Blocklist representation""" id = db.Column(db.Integer, primary_key=True) jti = db.Column(db.String(36), nullable=False, unique=True) token_type = db.Column(db.String(10), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) revoked = db.Column(db.Boolean, nullable=False) expires = db.Column(db.DateTime, nullable=False) user = db.relationship("User", lazy="joined") def to_dict(self): return { "token_id": self.id, "jti": self.jti, "token_type": self.token_type, "user_identity": self.user_identity, "revoked": self.revoked, "expires": self.expires, }
class TokenBlacklist(db.Model): """Blacklist representation """ id = db.Column(db.Integer, primary_key=True) jti = db.Column(db.String(36), nullable=False, unique=True) token_type = db.Column(db.String(10), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) revoked = db.Column(db.Boolean, nullable=False) expires = db.Column(db.DateTime, nullable=False) user = db.relationship('User', lazy='joined') def to_dict(self): return { 'token_id': self.id, 'jti': self.jti, 'token_type': self.token_type, 'user_identity': self.user_identity, 'revoked': self.revoked, 'expires': self.expires }