Created
August 8, 2016 23:33
-
-
Save maxtortime/ae48d7e0fa0dbd8deda1004bdec9983c to your computer and use it in GitHub Desktop.
flask-sqlalchemy 외래키 구현
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define models | |
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'))) | |
# Role table | |
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)) | |
# User's table | |
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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://pythonhosted.org/Flask-Security/quickstart.html#sqlalchemy-application