-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
68 lines (54 loc) · 2.48 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
from app import db, login_manager #
from flask_login import UserMixin
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(150))
email = db.Column(db.String(150), unique=True)
password = db.Column(db.String(256))
role = db.Column(db.String(50)) # 'manager' or 'housekeeper'
created_at = db.Column(db.DateTime, default=datetime.utcnow)
def set_password(self, password):
self.password = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password, password)
tasks = db.relationship('Task', backref='assigned_user', lazy='dynamic')
def __repr__(self):
return f'<User {self.email}>'
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class Task(db.Model):
__tablename__ = 'tasks'
id = db.Column(db.Integer, primary_key=True)
room_number = db.Column(db.String(50))
notes = db.Column(db.Text)
status = db.Column(db.String(50), default='pending') # 'pending', 'in_progress', 'completed'
priority = db.Column(db.Integer, default=3) # 1 (High) to 5 (Low)
service_type = db.Column(db.String(50)) # 'full_clean', 'refresh', 'items_only'
assigned_to = db.Column(db.Integer, db.ForeignKey('users.id'))
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
photos = db.relationship('Photo', backref='task', lazy='dynamic')
def __repr__(self):
return f'<Task Room {self.room_number}>'
class Photo(db.Model):
__tablename__ = 'photos'
id = db.Column(db.Integer, primary_key=True)
task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'))
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
filename = db.Column(db.String(256))
uploaded_at = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return f'<Photo {self.filename}>'
class Log(db.Model):
__tablename__ = 'logs'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
action = db.Column(db.String(256))
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
user = db.relationship('User')
def __repr__(self):
return f'<Log {self.action}>'