forked from muhamedhaamdy/LearnLogs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.py
93 lines (66 loc) · 3.75 KB
/
notes.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
# This file is used to test the models and the relationships between them
'''
from learnlogs import app, db
from learnlogs.models import Session, Student, Student_Session
with app.app_context():
db.create_all()
#to get saad and umar(students) from the database
saad = Student.query.filter_by(student_name='saad').first()
umar = Student.query.filter_by(student_name='umar').first()
#to get the session from the database
session = Session.query.filter_by(id=1).first()
#make saad and umar attend the session
saad.attended.append(session)
umar.attended.append(session)
db.session.commit()
#to get the students who attended the session
attended = session.attended_student --> #attended_student is the backref in the Session model
print(attended)
#to get the sessions attended by saad
saad_session = saad.attended --> #attended is the attribute in the Student model
print(saad_session)
'''
#to test the many to many relationship between the Student and the Session models
'''
from learnlogs import app, db
from sqlalchemy import select
from learnlogs.models import Session, Student, Student_Session
with app.app_context():
db.drop_all()
db.create_all()
#creating the students and the sessions
saad = Student(student_name='saad', email='[email protected]', password='password', student_phone='12345678901', parent_name='saad parent', parent_phone='12345678901', address='saad address', grade='first')
umar = Student(student_name='umar', email='[email protected]', password='password', student_phone='12345678901', parent_name='umar parent', parent_phone='12345678901', address='umar address', grade='first')
bor3y = Student(student_name='bor3y', email='[email protected]', password='password', student_phone='12345678901', parent_name='bor3y parent', parent_phone='12345678901', address='bor3y address', grade='first')
session1 = Session(grade='first')
session2 = Session(grade='first')
session3 = Session(grade='first')
db.session.add_all([saad, umar, bor3y, session1, session2, session3])
db.session.commit()
#creating the student_session entries for the students and the sessions
#mark is the mark the student got in the session
student_session_entry1 = Student_Session.insert().values(student_id=saad.id, session_id=session1.id, mark=7)
student_session_entry2 = Student_Session.insert().values(student_id=umar.id, session_id=session1.id, mark=8)
student_session_entry3 = Student_Session.insert().values(student_id=bor3y.id, session_id=session1.id, mark=9)
db.session.execute(student_session_entry1)
db.session.execute(student_session_entry2)
db.session.execute(student_session_entry3)
db.session.commit()
#to get the mark of the students in the session
saad_mark = db.session.query(Student_Session).filter(Student_Session.c.student_id == saad.id).first().mark
umar_mark = db.session.query(Student_Session).filter(Student_Session.c.student_id == umar.id).first().mark
bor3y_mark = db.session.query(Student_Session).filter(Student_Session.c.student_id == bor3y.id).first().mark
print(saad_mark)
print(umar_mark)
print(bor3y_mark)
'''
'''
لو انت عايزه يحضر عافيه من غير درجه هنعمل
saad.attended.append(session1)
لو عايزه يحضر بدرجه حتي لو صفر هنعمل كده
student_session_entry1 = Student_Session.insert().values(student_id=saad.id, session_id=session1.id, mark=7)
وتكتب الدرحه اللي عايزها في القيمه اللي هتتحط في الجدول
'''
#https://github.com/StartBootstrap/startbootstrap-landing-page
#https://github.com/zuramai/mazer?tab=readme-ov-file
#https://github.com/mdbootstrap/bootstrap-5-admin-template/