Flask-Project-Template/src/core/models.py

22 lines
629 B
Python
Raw Normal View History

2020-10-30 23:25:34 +00:00
2019-12-29 21:59:11 +00:00
from flask_sqlalchemy import SQLAlchemy
2020-03-14 08:43:04 +00:00
from core import app, login_manager
from flask_login import UserMixin
2019-12-29 21:59:11 +00:00
2019-12-22 19:09:36 +00:00
2020-03-14 08:43:04 +00:00
db = SQLAlchemy(app)
2019-12-22 19:09:36 +00:00
2020-03-14 08:43:04 +00:00
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
2020-03-14 08:43:04 +00:00
class User(db.Model, UserMixin):
username = db.Column(db.String, unique=True, nullable=False)
email = db.Column(db.String, nullable=False)
password = db.Column(db.String, nullable=False)
2020-03-14 22:17:50 +00:00
id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True)
def __repr__(self):
return f"['{self.username}', '{self.email}', '{self.password}', '{self.id}']"