class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) password = db.Column(db.String(50), nullable=False) ctime = db.Column(db.DateTime, nullable=False, default=datetime.now) utime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now) channels = db.relationship( 'Channel', secondary=UserChannel.__tablename__, back_populates='users', ) user_channel = db.relationship('UserChannel') def get_id(self): return 1 def get_auth_token(self): return hashlib.sha1(self.name + self.password).hexdigest()
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) active = db.Column( 'is_active', db.Boolean(), nullable=False, server_default='1') password = db.Column(db.String(255), nullable=False, server_default='') email = db.Column(EmailType, unique=True, nullable=False) email_confirmed_at = db.Column(db.DateTime()) full_name = db.Column(db.String(255), nullable=False, server_default='') def __repr__(self): return '<User %r>' % self.email
class User(UserMixin, SurrogatePK, Model): """A user of the app.""" __tablename__ = 'auth_users' username = Column(db.String(80), unique=True, nullable=False) email = Column(db.String(80), unique=True, nullable=True) #: The hashed password password = Column(db.Binary(128), nullable=False) created_at = Column(db.DateTime, nullable=False, default=dt.datetime.now) first_name = Column(db.String(30), nullable=True) last_name = Column(db.String(30), nullable=True) active = Column(db.Boolean(), default=False) is_admin = Column(db.Boolean(), default=False) sid = Column(db.String(80), nullable=True, default='') def __init__(self, username, password=None, **kwargs): """Create instance.""" db.Model.__init__(self, username=username, **kwargs) if password: self.set_password(password) else: self.password = None def set_password(self, password): """Set password.""" self.password = bcrypt.generate_password_hash(password) def check_password(self, value): """Check password.""" return bcrypt.check_password_hash(self.password, value) @property def full_name(self): """Full user name.""" return '{0} {1}'.format(self.first_name, self.last_name) def __repr__(self): """Represent instance as a unique string.""" return '<User({username!r})>'.format(username=self.username) def to_json(self): return { 'id': self.id, 'username': self.username, 'email': self.email, 'active': self.active, 'is_admin': self.is_admin, 'sid': self.sid, 'created_at': self.created_at.strftime("%Y-%m-%d %H:%M:%S") }
class SomeStuff(db.Model): __tablename__ = 'somestuff' id = db.Column(db.Integer, primary_key=True) data1 = db.Column(db.Integer) data2 = db.Column(db.String(10)) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) user = db.relationship(User, lazy='joined', join_depth=1, viewonly=True)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) last_login_at = db.Column(db.DateTime()) current_login_at = db.Column(db.DateTime()) last_login_ip = db.Column(db.String(255)) current_login_ip = db.Column(db.String(255)) login_count = db.Column(db.Integer) def __repr__(self): return '<models.User[email=%s]>' % self.email
class Answer(db.Model): __tablename__ = 'answers' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, nullable=False) question_id = db.Column(db.Integer, nullable=False) text = db.Column(db.String(255)) ctime = db.Column(db.DateTime, nullable=False, default=datetime.now) utime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(120), nullable=False) body = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) created_at = db.Column(db.DateTime, default=db.func.now()) def __init__(self, title, body): self.title = title self.body = body self.user_id = current_user.id def __repr__(self): return '<Post %r>' % self.title
class Question(db.Model): __tablename__ = 'questions' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), nullable=False) channel_id = db.Column(db.Integer, db.ForeignKey('channels.id'), nullable=False) ctime = db.Column(db.DateTime, nullable=False, default=datetime.now) utime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
class Role(SurrogatePK, Model): """A role for a user.""" __tablename__ = 'auth_roles' name = Column(db.String(80), unique=True, nullable=False) user_id = reference_col('auth_users', nullable=True) user = relationship('User', backref='roles') def __init__(self, name, **kwargs): """Create instance.""" db.Model.__init__(self, name=name, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return '<Role({name})>'.format(name=self.name)
class Channel(db.Model): __tablename__ = 'channels' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) ctime = db.Column(db.DateTime, nullable=False, default=datetime.now) utime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now) users = db.relationship( 'User', secondary=UserChannel.__tablename__, back_populates='channels', ) user_channel = db.relationship('UserChannel') @classmethod def get_channels(cls, user): return cls.query.filter(cls.id == user.id)
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))