universityModulesAPI.py 953 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from backend.models.university import University
2
from backend.models.campus import CampusSerializer
Florent Chehab's avatar
Florent Chehab committed
3
4

from backend.models.university import UniversityDriSerializer
5
from backend.models.my_model import MyModelSerializer, MyModelViewSet
6
from backend.utils import get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
7
8


9
class UniversityModulesSerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
10
11
12
13
14
15
16
17
    univ_campus = CampusSerializer(many=True, read_only=True)
    university_dri = UniversityDriSerializer(many=True, read_only=True)

    class Meta:
        model = University
        fields = '__all__'


18
class UniversityModulesViewSet(MyModelViewSet):
19
    permission_classes = get_viewset_permissions("UniversityModulesViewSet")
Florent Chehab's avatar
Florent Chehab committed
20
21
22
23
24
25
26
    serializer_class = UniversityModulesSerializer

    def get_queryset(self):
        univ_id = self.kwargs['univ_id']
        return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri')  # pylint: disable=E1101

    # queryset = get_queryset()