Blame view

app/models.py 3.67 KB
76ef4fbe   hitier   Click, Sqlalchemy...
1
from flask_sqlalchemy import SQLAlchemy
454728d5   hitier   Use sqlalchemy re...
2
from sqlalchemy.orm import relationship
76ef4fbe   hitier   Click, Sqlalchemy...
3
4
5
6

db = SQLAlchemy()


a2074730   hitier   Feed projects labels
7
8
9
10
11
12
13
14
15
16
#
# Categorized projects
#

class Project(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    labels = relationship("ProjectLabel", back_populates="project")


d6b9daca   hitier   Feed categories a...
17
18
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
a2074730   hitier   Feed projects labels
19
20
21
    name = db.Column(db.String)
    labels = relationship("Label", back_populates="category")
    projects = relationship("ProjectLabel", back_populates="category")
d6b9daca   hitier   Feed categories a...
22
23


a2074730   hitier   Feed projects labels
24
class Label(db.Model):
d6b9daca   hitier   Feed categories a...
25
    id = db.Column(db.Integer, primary_key=True)
a2074730   hitier   Feed projects labels
26
    name = db.Column(db.String, unique=True)
d6b9daca   hitier   Feed categories a...
27
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
a2074730   hitier   Feed projects labels
28
29
30
31
32
33
34
35
36
37
38
39
40
    category = relationship("Category", back_populates="labels")
    projects = relationship("ProjectLabel", back_populates="label")


class ProjectLabel(db.Model):
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'), primary_key=True)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'), primary_key=True)
    label_id = db.Column(db.Integer, db.ForeignKey('label.id'))

    project = relationship("Project", back_populates="labels")
    category = relationship("Category", back_populates="projects")
    label = relationship("Label", back_populates="projects")

d6b9daca   hitier   Feed categories a...
41

a2074730   hitier   Feed projects labels
42
43
44
#
# Agents
#
d6b9daca   hitier   Feed categories a...
45

ad3a824d   hitier   Add more agent fi...
46
47
48
class AgentBap(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16))
f3dbebc2   hitier   New agent relatio...
49
    agents = relationship("Agent", back_populates="bap")
ad3a824d   hitier   Add more agent fi...
50
51
52
53
54


class AgentGrade(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16))
f3dbebc2   hitier   New agent relatio...
55
    agents = relationship("Agent", back_populates="grade")
ad3a824d   hitier   Add more agent fi...
56
57
58
59
60


class AgentStatus(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16))
f3dbebc2   hitier   New agent relatio...
61
    agents = relationship("Agent", back_populates="status")
ad3a824d   hitier   Add more agent fi...
62
63
64
65
66


class Company(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16))
f3dbebc2   hitier   New agent relatio...
67
    agents = relationship("Agent", back_populates="company")
ad3a824d   hitier   Add more agent fi...
68
69


2784d9cc   hitier   Add models for ch...
70
71
72
73
class Agent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(100))
    secondname = db.Column(db.String(100))
f3dbebc2   hitier   New agent relatio...
74
75
    virtual = db.Column(db.Integer)  # integer boolean
    permanent = db.Column(db.Integer)  # integer boolean
ad3a824d   hitier   Add more agent fi...
76
77
78
79
    company_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    grade_id = db.Column(db.Integer, db.ForeignKey('agent_grade.id'))
    status_id = db.Column(db.Integer, db.ForeignKey('agent_status.id'))
    bap_id = db.Column(db.Integer, db.ForeignKey('agent_bap.id'))
f3dbebc2   hitier   New agent relatio...
80
81
82
83
    grade = relationship("AgentGrade", back_populates="agents")
    bap = relationship("AgentBap", back_populates="agents")
    status = relationship("AgentStatus", back_populates="agents")
    company = relationship("Company", back_populates="agents")
2784d9cc   hitier   Add models for ch...
84
85


2784d9cc   hitier   Add models for ch...
86
87
88
class Service(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
1002c994   hitier   Also feed ids fro...
89
    abbr = db.Column(db.String(50), unique=True)
2784d9cc   hitier   Add models for ch...
90
91


2784d9cc   hitier   Add models for ch...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
class Capacity(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)


class Period(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    num_months = db.Column(db.Integer)


class Charge(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    agent_id = db.Column(db.Integer, db.ForeignKey('agent.id'))
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
    service_id = db.Column(db.Integer, db.ForeignKey('service.id'))
582b4b3a   hitier   Add capacity comp...
108
    capacity_id = db.Column(db.Integer, db.ForeignKey('capacity.id'))
2784d9cc   hitier   Add models for ch...
109
110
    period_id = db.Column(db.Integer, db.ForeignKey('period.id'))
    charge_rate = db.Column(db.Integer)