-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
46 lines (34 loc) · 1.61 KB
/
models.py
File metadata and controls
46 lines (34 loc) · 1.61 KB
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
from sqlalchemy import Boolean, Column, ForeignKey, DateTime, Integer,\
String, Text, Float
from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy.orm import relationship, backref
from application.app import db
class Projects(db.Model):
__tablename__ = 'projects'
id = Column(Integer, primary_key=True)
name = Column(String(128), nullable=False, unique=True)
description = Column(Text, nullable=True, default="none")
def __repr__(self):
return (u'<{self.__class__.__name__}: {self.id}>'.format(self=self))
class Users(db.Model):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(String(100), nullable=False, unique=True)
password_hash = Column(String(128), nullable=False)
email = Column(String(200), nullable=True, default="none")
admin = Column(Boolean, nullable=False, default=False)
projects = relationship("Projects", secondary="user_project", backref='users')
def __repr__(self):
return (u'<{self.__class__.__name__}: {self.id}>'.format(self=self))
@property
def password(self):
raise AttributeError('password is not a readable attribute')
@password.setter
def password(self, password):
self.password_hash = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
user_project = db.Table('user_project',
db.Column('project_id', db.Integer, db.ForeignKey('projects.id'), primary_key=True),
db.Column('user_id', db.Integer, db.ForeignKey('users.id'), primary_key=True)
)