-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
109 lines (74 loc) · 3.62 KB
/
model.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""Models and database functions for HB Spring 2015 Final project."""
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
db = SQLAlchemy()
class User(db.Model):
"""User"""
__tablename__ = "user"
user_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
first_name = db.Column(db.String(100), nullable=False)
last_name = db.Column(db.String(100), nullable=False)
password = db.Column(db.String(64), nullable=True)
picture = db.Column(db.String(100))
email_address = db.Column(db.String(100))
linkedin_url = db.Column(db.String(100))
twitter_url = db.Column(db.String(100))
facebook_url = db.Column(db.String(100))
website_url = db.Column(db.String(100))
def __repr__(self):
"""This will provide helpful information when printed."""
return "<User user_id=%s first_name=%s>" % (self.user_id, self.first_name)
class Position(db.Model):
"""User's Positions"""
__tablename__ = "positions"
position_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
title = db.Column(db.String(50))
position_summary = db.Column(db.String(300))
deadline = db.Column(db.DateTime)
company_name = db.Column(db.String(100))
location = db.Column(db.String(100))
application_status = db.Column(db.String(50))
position_url = db.Column(db.String(100))
user = db.relationship("User", backref=db.backref("positions", order_by=position_id))
def __repr__(self):
"""Provide helpful representation when printed."""
return "<Positions position_id=%s title=%s user_id=%s deadline=%s>" % (self.position_id, self.title, self.user_id, self.deadline)
class Documents(db.Model):
"""User's Job Applicaton Documents."""
__tablename__ = "documents"
document_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
position_id = db.Column(db.Integer, db.ForeignKey('positions.position_id'), nullable=False)
document_type = db.Column(db.String(100))
document_content = db.Column(db.String(3000))
position = db.relationship("Position", backref=db.backref("documents", order_by=document_id))
class Notes(db.Model):
"""User's Notes."""
__tablename__ = "notes"
note_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
position_id = db.Column(db.Integer, db.ForeignKey('positions.position_id'), nullable=False)
note_details = db.Column(db.String(3000))
position = db.relationship("Position", backref=db.backref("notes", order_by=note_id))
class Contact(db.Model):
"""User's Contacts."""
__tablename__ = "contacts"
contact_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
position_id = db.Column(db.Integer, db.ForeignKey('positions.position_id'), nullable=False)
name = db.Column(db.String(100))
email_address = db.Column(db.String(100))
phone_number = db.Column(db.String(100))
position = db.relationship("Position", backref=db.backref("contacts", order_by=contact_id))
##############################################################################
# Helper functions
def connect_to_db(app):
"""Connect the database to our Flask app."""
# Configure to use our SQLite database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///thehunt.db'
db.app = app
db.init_app(app)
if __name__ == "__main__":
# As a convenience, if we run this module interactively, it will leave
# you in a state of being able to work with the database directly.
from server import app
connect_to_db(app)
print "Connected to DB."