-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
48 lines (36 loc) · 1.54 KB
/
models.py
File metadata and controls
48 lines (36 loc) · 1.54 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
47
48
from extensions import db
class Event(db.Model):
__tablename__ = 'events'
event_id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
start_time = db.Column(db.DateTime, nullable=False)
end_time = db.Column(db.DateTime, nullable=False)
description = db.Column(db.Text)
allocations = db.relationship(
'EventResourceAllocation',
back_populates='event',
cascade='all, delete'
)
def __repr__(self):
return f"<Event {self.title}>"
class Resource(db.Model):
__tablename__ = 'resources'
resource_id = db.Column(db.Integer, primary_key=True)
resource_name = db.Column(db.String(100), nullable=False)
resource_type = db.Column(db.String(50), nullable=False)
allocations = db.relationship(
'EventResourceAllocation',
back_populates='resource',
cascade='all, delete'
)
def __repr__(self):
return f"<Resource {self.resource_name}>"
class EventResourceAllocation(db.Model):
__tablename__ = 'event_resource_allocations'
allocation_id = db.Column(db.Integer, primary_key=True)
event_id = db.Column(db.Integer, db.ForeignKey('events.event_id'), nullable=False)
resource_id = db.Column(db.Integer, db.ForeignKey('resources.resource_id'), nullable=False)
event = db.relationship('Event', back_populates='allocations')
resource = db.relationship('Resource', back_populates='allocations')
def __repr__(self):
return f"<Allocation Event {self.event_id} - Resource {self.resource_id}>"