universityScholarship.py 1.17 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
3
4
from backend_app.models.university import University
from backend_app.models.abstract.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend_app.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
5
6
7


class UniversityScholarship(Scholarship):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("UniversityScholarship")
9
10
    universities = models.ManyToManyField(
        University, related_name="university_scholarships")
Florent Chehab's avatar
Florent Chehab committed
11

12
13
14
15
    @classmethod
    def get_serializer(cls):
        return UniversityScholarshipSerializer

Florent Chehab's avatar
Florent Chehab committed
16

17
class UniversityScholarshipSerializer(ScholarshipSerializer):
18
    FORCE_FULL_DISPLAY = True
Florent Chehab's avatar
Florent Chehab committed
19
20
21

    class Meta:
        model = UniversityScholarship
Florent Chehab's avatar
Florent Chehab committed
22
        fields = '__all__'
Florent Chehab's avatar
Florent Chehab committed
23
24


25
class UniversityScholarshipViewSet(ScholarshipViewSet):
26
27
    permission_classes = get_viewset_permissions(
        "UniversityScholarshipViewSet")
Florent Chehab's avatar
Florent Chehab committed
28
29
    queryset = UniversityScholarship.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityScholarshipSerializer
30
31
32
33
34
35

    BYPASS_DICT_MODE = True

    def extend_queryset(self):
        univ_id = self.kwargs['univ_id']
        return self.my_model_queryset.filter(universities__pk=univ_id).distinct()