I would like it to show me the courses by user. I would need you to do the following but with the id of the user who logs in, since right now the code shows me the exams in general and I still need to add the id, and I don't know how to add the id of the user who is using the system.
Example:
SELECT * FROM quiz_course c WHERE NOT EXISTS ( SELECT * FROM quiz_result r, testing_testing t WHERE r.exam_id = c.id and t.id = 3);
Views: (this part of the code is the one I need to correct and t.id = id
)
@login_required(login_url='testinglogin')
@user_passes_test(is_testing)
def testing_exam_view(request):
con = MySQLdb.connect(user='root', db='dataevaluat', passwd='', host='localhost')
with con:
cur = con.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM quiz_course c WHERE NOT EXISTS ( SELECT * FROM quiz_result r, testing_testing t WHERE r.exam_id = c.id and |t.id = id|;")
courses = cur.fetchall()
for c in courses:
print(c)
return render(request, 'testing/testing_exam.html', {'courses': courses})
The logged in user information lives in the request object of your function as indicated in the Django User authentication documentation.
Following that premise you can modify your code as follows: