-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
87 lines (67 loc) · 2.46 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from app import db, bcrypt
from sqlalchemy.ext.hybrid import hybrid_property
events_categories_association = db.Table(
"events_categories",
db.metadata,
db.Column("event_id", db.Integer, db.ForeignKey("events.id")),
db.Column("category_id", db.Integer, db.ForeignKey("categories.id"))
)
class Event(db.Model):
__tablename__ = "events"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String)
host_name = db.Column(db.String)
url = db.Column(db.String)
planned_start = db.Column(db.DateTime)
planned_end = db.Column(db.DateTime)
estimated_duration = db.Column(db.Integer)
description = db.Column(db.String)
categories = db.relationship(
"Category",
secondary=events_categories_association
)
def __init__(
self,
title,
host_name,
url,
categories,
planned_start,
estimated_duration,
description
):
self.title = title
self.host_name = host_name
self.url = url
self.categories = categories
self.planned_start = planned_start
self.estimated_duration = estimated_duration
self.description = description
def __repr__(self):
return "{}".format(self.title)
class Category(db.Model):
__tablename__ = "categories"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String, nullable=False, unique=True)
def __init__(self, title):
self.title = title
def __repr__(self):
return "{}".format(self.title)
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(64), nullable=False, unique=True)
email = db.Column(db.String, nullable=False, unique=True)
_password = db.Column(db.String(128), nullable=False)
@hybrid_property
def password(self):
return self._password
@password.setter
def _set_password(self, password):
self._password = bcrypt.generate_password_hash(password)
def __init__(self, username, email, password):
self.username = username
self.email = email
self._password = bcrypt.generate_password_hash(password)
def __repr__(self):
return "{}".format(self.username)