This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
55 lines (38 loc) · 1.41 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import datetime
from flask_security.core import RoleMixin, UserMixin
from app import db, ma
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")),
)
class Role(db.Model, RoleMixin):
__tablename__ = "role"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
def __str__(self):
return self.name
class User(db.Model, UserMixin):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
phone = db.Column(db.String(12), nullable=False)
content = db.Column(db.String(200), nullable=False)
pwd = db.Column(db.String(300), nullable=False, unique=True)
fs_uniquifier = db.Column(db.String(64), unique=True, nullable=False)
roles = db.relationship(
"Role", secondary=roles_users, backref=db.backref("users", lazy="joined")
)
def active(self):
return True
def is_active(self):
return True
def __repr__(self):
return "<User %r" % self.email
class UserSchema(ma.Schema):
class Meta:
# fields = ("username", "email")
fields = ("username", "email", "phone", "content")
user_schema = UserSchema()
users_schema = UserSchema(many=True)