Skip to content

Instantly share code, notes, and snippets.

@ihfazhillah
Created July 11, 2019 04:47
Show Gist options
  • Save ihfazhillah/0c4087315728faa92544c2c44f2ef1e6 to your computer and use it in GitHub Desktop.
Save ihfazhillah/0c4087315728faa92544c2c44f2ef1e6 to your computer and use it in GitHub Desktop.
def detail_quiz(request, pk):
quiz = get_object_or_404(Quiz, pk=pk)
context = {
'quiz': quiz
}
allowed_see_questions = any([
request.user == quiz.created_by,
request.user in quiz.students.all()
])
if allowed_see_questions:
context['questions'] = Question.objects.filter(quiz=quiz)
return render_template(request, templatename, context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment