53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
from django.shortcuts import render
|
|
from rest_framework import generics
|
|
from .models import *
|
|
from .serializers import *
|
|
|
|
|
|
# Create your views here.
|
|
|
|
class ListDriverView(generics.ListAPIView):
|
|
"""
|
|
Provides a get method handler.
|
|
"""
|
|
queryset = Driver.objects.all()
|
|
serializer_class = DriverSerializer
|
|
|
|
class ListRaceView(generics.ListAPIView):
|
|
queryset = Race.objects.all()
|
|
serializer_class = RaceSerializer
|
|
|
|
class ListRelayView(generics.ListAPIView):
|
|
queryset = Relay.objects.all()
|
|
serializer_class = RelaySerializer
|
|
|
|
class ListRulesView(generics.ListAPIView):
|
|
queryset = Rules.objects.all()
|
|
serializer_class = RulesSerializer
|
|
|
|
class ListTeamView(generics.ListAPIView):
|
|
queryset = Team.objects.all()
|
|
serializer_class = TeamSerializer
|
|
|
|
class ListTeamPilotView(generics.ListAPIView):
|
|
queryset = TeamPilot.objects.all()
|
|
serializer_class = TeamPilotSerializer
|
|
|
|
|
|
class ListRelaysByRaceAndTeamView(generics.ListAPIView):
|
|
"""
|
|
Getting the params from the url with the "self.kwargs.get"
|
|
and filter with thoses in the relays relation
|
|
"""
|
|
serializer_class = RelayPilotSerializer
|
|
lookup_url_raceid = "raceid"
|
|
lookup_url_teamid = "teamid"
|
|
|
|
def get_queryset(self):
|
|
raceid = self.kwargs.get(self.lookup_url_raceid)
|
|
teamid = self.kwargs.get(self.lookup_url_teamid)
|
|
relays = Relay.objects.filter(team_pilot__team=teamid).filter(team_pilot__race=raceid)
|
|
return relays |