Ejemplo n.º 1
0
class Tag(DB.Model):
    id = DB.Column(DB.Integer, primary_key=True)
    name = DB.Column(DB.String(100), unique=True, nullable=False)

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return '<Tag %r>' % (self.name)
Ejemplo n.º 2
0
class User(DB.Model):
    """user accounts"""

    identifier = DB.Column('user_id',
                           DB.Integer,
                           primary_key=True,
                           autoincrement=True)
    username = DB.Column(DB.String(20),
                         unique=True,
                         index=True,
                         nullable=False)
    password = DB.Column(DB.String(10), nullable=False)
    email = DB.Column(DB.String(50), unique=True, index=True, nullable=False)
    role = DB.Column(DB.Text, nullable=False, default='user')
    registered_on = DB.Column(DB.DateTime)

    def __init__(self, username, password, email, role='user'):
        self.username = username
        self.password = password
        self.email = email
        self.role = role
        self.registered_on = datetime.utcnow()

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return unicode(self.identifier)

    def __repr__(self):
        return '<User %r>' % (self.username)