universityScholarship.py 845 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.university import University
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 UniversityScholarship(Scholarship):
11

12
    universities = models.ManyToManyField(
13
14
        University, related_name="university_scholarships"
    )
Florent Chehab's avatar
Florent Chehab committed
15
16


17
class UniversityScholarshipSerializer(ScholarshipSerializer):
Florent Chehab's avatar
Florent Chehab committed
18
19
    class Meta:
        model = UniversityScholarship
20
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
21
22


23
class UniversityScholarshipViewSet(ScholarshipViewSet):
Florent Chehab's avatar
Florent Chehab committed
24
25
    queryset = UniversityScholarship.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityScholarshipSerializer
26

27
    def get_queryset(self):
28
        univ_id = self.kwargs["univ_id"]
29
        return super().get_queryset().filter(universities__pk=univ_id).distinct()