-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpopulate_stu_section.py
More file actions
39 lines (29 loc) · 978 Bytes
/
populate_stu_section.py
File metadata and controls
39 lines (29 loc) · 978 Bytes
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
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sen.settings')
import django
django.setup()
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','EL203','MU12', 'OP125']
default_stud_password =['password']
def populate_students_courses(N=3):
users = []
#Create 3 users
for _ in range(N):
user = User(username=fake.name(),password = default_stud_password)
users.append(user)
user.save()
#create 3 prof with related to users created above, add courses
for i in range(N):
stud = Student(user=users[i],courses = random.choice(courses))
stud.save()
if __name__=='__main__':
print("Populating Student records!")
populate_students_courses()
print("Complete!")
print("---------------------------------------")