-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
135 lines (106 loc) · 4.08 KB
/
models.py
File metadata and controls
135 lines (106 loc) · 4.08 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
# Import needed libraries
from web import db
# Database schema class for client
class Client(db.Model):
# Declare table name as clients
__tablename__ = "client"
# Declare client's username as primary key
username = db.Column(db.String(16), primary_key=True)
# Declare other client fields
password = db.Column(db.String(16))
email = db.Column(db.String(24))
balance = db.Column(db.Float)
reveal = db.Column(db.String(8))
score = db.Column(db.Float)
type = db.Column(db.String(8))
amount = db.Column(db.Float)
frequency = db.Column(db.String(8))
checkbox = db.Column(db.String(8))
app = db.Column(db.String(8))
# Initialize class with basic info
def __init__(self, username, password, email, balance):
self.username = username
self.password = password
self.email = email
self.balance = balance
self.score = 0
self.reveal = "false"
self.type = "percent"
self.amount = None
self.frequency = None
self.checkbox = "show"
self.app = "disable"
# Print class as < username >
def __repr__(self):
return "<" + self.username + ">"
class DonatesTo(db.Model):
# Declare table name as donates_to
__tablename__ = "donates_to"
# Declare client's username and charity's name as primary key
client = db.Column(db.String(16), db.ForeignKey("client.username"), primary_key=True)
charity = db.Column(db.String(16), db.ForeignKey("charity.image"), primary_key=True)
# Initialize class with client and charity
def __init__(self, client, charity):
self.client = client
self.charity = charity
class Charity(db.Model):
# Declare table name as charity
__tablename__ = "charity"
# Declare charity's name as primary key
name = db.Column(db.String(36), primary_key=True)
# Declare other charity fields
image = db.Column(db.String(16), unique=True)
description = db.Column(db.Text)
investment = db.Column(db.Text)
# Initialize class with basic info
def __init__(self, name, image, description, investment=None):
self.name = name
self.image = image
self.description = description
self.investment = investment
# Print class as <name>
def __repr__(self):
return "<" + self.name + ">"
class Achieved(db.Model):
# Declare table name as achieved
__tablename__ = "achieved"
# Declare client's username and award's name as primary key
client = db.Column(db.String(16), db.ForeignKey("client.username"), primary_key=True)
award = db.Column(db.String(16), db.ForeignKey("award.image"), primary_key=True)
# Initialize class with client and award
def __init__(self, client, award):
self.client = client
self.award = award
class Award(db.Model):
# Declare table name as award
__tablename__ = "award"
# Declare award's name as primary key
name = db.Column(db.String(36), primary_key=True)
# Declare other award fields
image = db.Column(db.String(16), unique=True)
description = db.Column(db.Text)
# Initialize class with basic info
def __init__(self, name, image, description):
self.name = name
self.image = image
self.description = description
# Print class as <name>
def __repr__(self):
return "<" + self.name + ">"
class Donation(db.Model):
# Declare table name as donation
__tablename__ = "donation"
# Declare donation's date as primary key
date = db.Column(db.DateTime, primary_key=True)
# Declare other donation fields
amount = db.Column(db.Float)
client = db.Column(db.String(16), db.ForeignKey("client.username"))
# Initialize class with date, amount and client username
def __init__(self, client, date, amount):
self.date = date
self.amount = amount
self.client = client
# Print class as <username, Date: dd/mm/yy, Amount: amount>
def __repr__(self):
return "<" + self.client + ", Date: " + self.date.strftime("%d/%m/%y") + ", Amount: " + str(self.amount) + ">"