Last active
March 16, 2017 12:51
-
-
Save exit99/934a21ddea24a6f06088dd4f5cb14208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will return None if not found, as opposed to raising an exception | |
classroom = Classroom.objects.filter(pk=pk).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import get_object_or_404 | |
# This will return a HTTP 404 response if the objects does not exist | |
classroom = get_object_or_404(Classroom, pk=pk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
classroom = Classroom.objects.get(pk=pk) | |
except Classroom.DoesNotExist: | |
classroom = None | |
questions = Question.objects.filter(classroom=classroom).order_by('-created') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment