• 12 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 3/2/22

Use Advanced Functionalities of the Django ORM and Templates

Evaluated skills

  • Use advanced functionalities of the Django ORM and templates

Description

Refer to the following scenario for the quiz questions: 

You are working on a Django application that tracks the results of athletic races. The application contains the following models:

class Race(models.Model):
name = models.CharField()
event_start = models.DateTimeField()
class Athlete(models.Model):
first_name = models.CharField()
last_name = models.CharField()
date_of_birth =models.DateField()
class RaceResult(models.Model):
athlete = models.ForeignKey(Athlete)
race = models.ForeignKey(Race)
position = models.IntegerField()
  • Question 1

    The events organizer wants to send a message to all of the athletes who have competed in the  Park Run  event. 

    Select the query that returns all of these athletes. 

    • Athlete.objects.filter(raceresult__race__name='Park Run')

    • Race.objects.filter(name='Park Run')

    • RaceResult.objects.filter(race__name='Park Run')

    • Athlete.objects.filter(race__name='Park Run')

  • Question 2

    What does the following query do?

    from datetime import datetime
    Athlete.objects.filter(
    raceresult__position__lte=3,
    date_of_birth__gte=datetime(day=1, month=1, year=2000))
    • Selects the athletes who finished 3rd or worse in a race and were born on or before 2000.

    • Selects the athletes who have finished 3rd or better in a race and were born on or after 2000.

    • Selects the athletes who finished 3rd or better in a race or were born on or after 2000.

    • Selects the athletes who have finished 3rd or worse in a race or were born on or after 2000.

  • Question 3

    You are curating an invitation-only race that is open to athletes who have either:

    * Placed 1st in any race.

    * Placed in the top three of a Marathon  race.

    Select the query that retrieves the QuerySet of eligible athletes.

    • Athlete.objects.filter(raceresult__position = 1, (raceresult__position__lte=3, raceresult__race__name='Marathon'))

    • Athlete.objects.filter(Q(raceresult__position = 1) | ~Q(raceresult__position__lte=3, raceresult__race__name='Marathon'))

    • Athlete.objects.filter(Q(raceresult__position = 1) & Q(raceresult__position__lte=3, raceresult__race__name='Marathon'))

    • Athlete.objects.filter(Q(raceresult__position = 1) | Q(raceresult__position__lte=3, raceresult__race__name='Marathon'))

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best