countryScholarship.py 804 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from backend_app.models.country import Country
3
4
5
6
7
from backend_app.models.abstract.scholarship import (
    Scholarship,
    ScholarshipSerializer,
    ScholarshipViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
8
9
10


class CountryScholarship(Scholarship):
11

12
    countries = models.ManyToManyField(Country, related_name="country_scholarships")
Florent Chehab's avatar
Florent Chehab committed
13
14


15
class CountryScholarshipSerializer(ScholarshipSerializer):
Florent Chehab's avatar
Florent Chehab committed
16
17
    class Meta:
        model = CountryScholarship
18
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
19
20


21
class CountryScholarshipViewSet(ScholarshipViewSet):
Florent Chehab's avatar
Florent Chehab committed
22
23
    queryset = CountryScholarship.objects.all()  # pylint: disable=E1101
    serializer_class = CountryScholarshipSerializer
24

25
    def get_queryset(self):
26
        country_id = self.kwargs["country_id"]
27
        return super().get_queryset().filter(countries__pk=country_id).distinct()