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): __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): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text) email = db.Column(db.Text) def __repr__(self): return f"<User> id={self.id}, name={self.name}, email={self.email}"
class PostTime(db.Model): __tablename__ = 'post_time' id = db.Column(db.Integer, primary_key=True) channel_id = db.Column(db.Integer, db.ForeignKey('channels.id'), nullable=False) post_time = db.Column(db.DateTime, nullable=False)
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 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 UserChannel(db.Model): __tablename__ = 'users_channels' user_id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True) channel_id = db.Column(db.Integer, db.ForeignKey('channels.id'), primary_key=True) ctime = db.Column(db.DateTime, nullable=False, default=datetime.now) utime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now) user = db.relationship('User') channel = db.relationship('Channel')
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 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 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 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))
# -*- coding: utf-8 -*- from flask.ext.security import UserMixin, RoleMixin, SQLAlchemyUserDatastore from apps.database import db roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) 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 Role(db.Model, RoleMixin):