universityDri.py 1.03 KB
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.basic_module import (
    BasicModule,
    BasicModuleSerializer,
    BasicModuleViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
8
from backend_app.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
9 10


11
class UniversityDri(BasicModule):
Florent Chehab's avatar
Florent Chehab committed
12
    model_config = get_model_config("UniversityDri")
13
    universities = models.ManyToManyField(University, related_name="university_dri")
Florent Chehab's avatar
Florent Chehab committed
14

15 16 17 18
    @classmethod
    def get_serializer(cls):
        return UniversityDriSerializer

Florent Chehab's avatar
Florent Chehab committed
19

20
class UniversityDriSerializer(BasicModuleSerializer):
Florent Chehab's avatar
Florent Chehab committed
21 22
    class Meta:
        model = UniversityDri
23
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
24 25


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

31
    def get_queryset(self):
32
        univ_id = self.kwargs["univ_id"]
33
        return super().get_queryset().filter(universities__pk=univ_id).distinct()