universityAPI.py 799 Bytes
Newer Older
1
from backend.models.university import University
2
from rest_framework import viewsets, permissions
3
from backend.models.university.campus import CampusSerializer
4
from backend.models.tools import NoDeleteIfNotAdmin
Florent Chehab's avatar
Florent Chehab committed
5
from backend.models.moderation import MyModelSerializer
6
7


8
class UniversitySerializer(MyModelSerializer):
9
    univ_campus = CampusSerializer(many=True, read_only=True)
10
11
12

    class Meta:
        model = University
13
        fields = '__all__'
14
15
16


class UniversityViewSet(viewsets.ModelViewSet):  # TODO switch to dict
17
18
19
20
21
22
    permission_classes = (
        permissions.IsAuthenticated,
        NoDeleteIfNotAdmin,
    )
    queryset = University.objects.all()\
        .prefetch_related('univ_campus', 'univ_campus__updated_by')  # pylint: disable=E1101
23
    serializer_class = UniversitySerializer