Permalink
Switch branches/tags
Nothing to show
Find file Copy path
6fe45fe Jun 26, 2013
1 contributor

Users who have contributed to this file

58 lines (41 sloc) 1.61 KB
# -*- coding: utf-8 -*-
"""
overholt.users.models
~~~~~~~~~~~~~~~~~~~~~
User models
"""
from flask_security import UserMixin, RoleMixin
from ..core import db
from ..helpers import JsonSerializer
roles_users = db.Table(
'roles_users',
db.Column('user_id', db.Integer(), db.ForeignKey('users.id')),
db.Column('role_id', db.Integer(), db.ForeignKey('roles.id')))
class Role(RoleMixin, db.Model):
__tablename__ = 'roles'
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))
def __eq__(self, other):
return (self.name == other or
self.name == getattr(other, 'name', None))
def __ne__(self, other):
return (self.name != other and
self.name != getattr(other, 'name', None))
class UserJsonSerializer(JsonSerializer):
__json_public__ = ['id', 'email']
class User(UserJsonSerializer, UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(255), unique=True)
password = db.Column(db.String(120))
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)
registered_at = db.Column(db.DateTime())
roles = db.relationship('Role', secondary=roles_users,
backref=db.backref('users', lazy='dynamic'))