-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
66 lines (50 loc) · 2.04 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
56
57
58
59
60
61
62
63
64
65
66
from database import Base
from flask_security import UserMixin, RoleMixin
from sqlalchemy import create_engine
from sqlalchemy.orm import relationship, backref
from sqlalchemy.sql import func
from sqlalchemy import Boolean, DateTime, Column, Integer, \
String, ForeignKey
class RolesUsers(Base):
__tablename__ = 'roles_users'
id = Column(Integer(), primary_key=True)
user_id = Column('user_id', Integer(), ForeignKey('user.id'))
role_id = Column('role_id', Integer(), ForeignKey('role.id'))
class Role(Base, RoleMixin):
__tablename__ = 'role'
id = Column(Integer(), primary_key=True)
name = Column(String(80), unique=True, nullable=False)
description = Column(String(255))
def __unicode__(self):
return self.name
def __repr__(self):
return "{}: {}".format(self.name, self.description)
class User(Base, UserMixin):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
email = Column(String(255), unique=True, nullable=False)
username = Column(String(255), unique=True, nullable=False)
password = Column(String(255))
last_login_at = Column(DateTime())
current_login_at = Column(DateTime())
last_login_ip = Column(String(100))
current_login_ip = Column(String(100))
login_count = Column(Integer)
active = Column(Boolean())
confirmed_at = Column(DateTime())
roles = relationship('Role', secondary='roles_users',
backref=backref('users', lazy='dynamic'))
def __unicode__(self):
return self.username
def __repr__(self):
return "{} <{}>".format(self.username, self.email)
class Category(Base):
__tablename__ = 'categories'
id = Column(Integer(), primary_key=True)
name = Column(String(255), nullable=False)
created_at = Column(DateTime(timezone=True), default=func.now())
updated_at = Column(DateTime(timezone=True), default=func.now(), onupdate=func.now())
def __unicode__(self):
return self.name
def __repr__(self):
return "{}".format(self.name)