-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_rating.py
31 lines (26 loc) · 910 Bytes
/
populate_rating.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
import os
import django
import random
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'setup.settings')
django.setup()
from accounts.models import Student, Teacher, Rating
def populate_ratings():
data =[
{
"student": random.choice(Student.objects.values_list('id', flat=True)),
"teacher": random.choice(Teacher.objects.values_list('id', flat=True)),
"rating": round(random.uniform(0, 5.0) * 2) / 2,
"comment": f"Comentário Aleatório {i}"
} for i in range(0, 60)
]
for value in data:
student = Student.objects.get(id=value["student"])
teacher = Teacher.objects.get(id=value["teacher"])
Rating.objects.create(
student=student,
teacher=teacher,
rating=value["rating"],
comment=value["comment"]
)
if __name__ == "__main__":
populate_ratings()