This repository was archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
72 lines (53 loc) · 2.35 KB
/
database.py
File metadata and controls
72 lines (53 loc) · 2.35 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
# flask_graphene_mongo/database.py
#imports necessary objects from modules
from mongoengine import connect
from models import Location, Textbook, Professor, CourseMetrics, Course
#sets up the GraphQL interface on the local host's system
connect('graphene-mongo-example', host='mongomock://localhost', alias='default')
"""
init_db: Creates dummy data that can be accessed and traversed through Queries.
args: None
returns: None
"""
def init_db():
# Create the fixtures
location1 = Location(name = 'North', building_name = 'Bill Building', room_number = "15", latitude = '15 N', longitude = '30 W')
location1.save()
location2 = Location(name = 'South', building_name = 'Tim Building', room_number = "12", latitude = '15 S', longitude = '30 E')
location2.save()
textbook1 = Textbook(name = 'Intro to Python Programming', author = "Richard Brand", isbn = "9187434556789")
textbook1.save()
textbook2 = Textbook(name = 'Intro to C Programming', author = "Chris Lin", isbn = "4782901283451")
textbook2.save()
professor1 = Professor(name = 'Robert Dawson')
professor1.save()
professor2 = Professor(name = 'Jack Walsh')
professor2.save()
course1 = Course(name = 'CSC 357', metrics = CourseMetrics(homework_hours_per_week = "6", average_pass_rate = '60%'), professor = professor1, textbook = textbook1, course_location = location1)
course1.save()
course2 = Course(name = 'CSC 358', metrics = CourseMetrics(homework_hours_per_week = "8", average_pass_rate = '40%'), professor = professor2, textbook = textbook2, course_location = location1)
course2.save()
professor1.course = course1
professor1.textbook = textbook1
professor1.location = location1
professor1.save()
professor2.course = course2
professor2.textbook = textbook2
professor2.location = location2
professor2.save()
location1.courses = [course1, course2]
location1.textbook = textbook1
location1.professor = professor1
location1.save()
location2.course = [course2]
location2.textbook = textbook2
location2.professor = professor2
location2.save()
textbook1.courses = [course1]
textbook1.professor = professor1
textbook1.location = location1
textbook1.save()
textbook2.courses = [course2]
textbook2.professor = professor2
textbook2.location = location2
textbook2.save()