universityDri.py 1.05 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.university import University
3
from backend.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
Florent Chehab's avatar
Florent Chehab committed
4
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
5
6


7
class UniversityDri(BasicModule):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("UniversityDri")
9
    universities = models.ManyToManyField(
Florent Chehab's avatar
Florent Chehab committed
10
11
        University, related_name="university_dri")

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

Florent Chehab's avatar
Florent Chehab committed
16

17
class UniversityDriSerializer(BasicModuleSerializer):
Florent Chehab's avatar
Florent Chehab committed
18
19
20
21
22
23

    class Meta:
        model = UniversityDri
        fields = '__all__'


24
class UniversityDriViewSet(BasicModuleViewSet):
25
    permission_classes = get_viewset_permissions("UniversityDriViewSet")
Florent Chehab's avatar
Florent Chehab committed
26
27
    queryset = UniversityDri.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityDriSerializer
28
29
30
31
32
33

    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()