Esempio n. 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(255))
    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())
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(100))
    current_login_ip = db.Column(db.String(100))
    login_count = db.Column(db.Integer())
    roles = db.relationship(
        'Role',
        secondary=role_users,
        backref=db.backref('users', lazy='dynamic')
    )

    def get_security_payload(self):
        return {
            'id': self.id,
            'name': self.name,
            'email': self.email,
        }

    def __str__(self):
        return self.email
class Article(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)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User, backref=db.backref('articles', uselist=True))

    def __repr__(self):
        return '<Article %s>' % self.title
Esempio n. 3
0
class Tag(SurrogatePK, Model):

    __tablename__ = 'tags'

    tag = db.Column(db.Text)
    posts = db.relationship('Post', secondary=tags_posts, backref=db.backref('tags_br', lazy='dynamic'))

    def __init__(self, tag, **kwargs):
        db.Model.__init__(self, tag=tag, **kwargs)
Esempio n. 4
0
class Post(SurrogatePK, Model):

    __tablename__ = 'posts'

    title = db.Column(db.Text)
    slug = db.Column(db.Text)
    body = db.Column(db.Text)
    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    tags = db.relationship('Tag', secondary=tags_posts, backref=db.backref('posts_br', lazy='dynamic'))

    def __init__(self, title, slug, body, **kwargs):
        db.Model.__init__(self, title=title, slug=slug, body=body, **kwargs)
Esempio n. 5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)

    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))