-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpopulate_prof_section.py
More file actions
57 lines (44 loc) · 1.35 KB
/
populate_prof_section.py
File metadata and controls
57 lines (44 loc) · 1.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
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sen.settings')
import django
django.setup()
#adding fake data
import random
from prof_section.models import AttendanceRecord,Prof
from stu_section.models import Student
from django.contrib.auth.models import User
from faker import Faker
fake = Faker()
#ids = ['201701131','201701130','201701138','201701133']
courses= ['IT413','CS203','HM413','IT303']
default_prof_password ='password'
def add_attendance_record():
student = random.choice(Student.objects.all())
username = student.user.username
courseIDs = student.courses.split(" ")
record = AttendanceRecord.objects.get_or_create(
studentID=username, courseID= random.choice(courseIDs))[0]
record.save()
return record
def populate_attendance(N=5):
for entry in range(N):
add_attendance_record()
def populate_profs(N=3):
users = []
#Create 3 users
for _ in range(N):
user = User(username=fake.name(),password = default_prof_password)
users.append(user)
user.save()
#create 3 prof with related to users created above, add courses
for i in range(N):
prof = Prof(user=users[i],courses = courses[i])
prof.save()
if __name__=='__main__':
print("Populating attendance records!")
populate_attendance()
print("Complete!")
print("---------------------------------------")
print("Populating Profs!")
populate_profs()
print("Complete!")