universityDri.py 808 Bytes
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
from backend_app.models.abstract.module import Module, ModuleSerializer, ModuleViewSet
Florent Chehab's avatar
Florent Chehab committed
4 5


6
class UniversityDri(Module):
7

8
    universities = models.ManyToManyField(University, related_name="university_dri")
Florent Chehab's avatar
Florent Chehab committed
9

10 11 12 13
    @classmethod
    def get_serializer(cls):
        return UniversityDriSerializer

Florent Chehab's avatar
Florent Chehab committed
14

15
class UniversityDriSerializer(ModuleSerializer):
Florent Chehab's avatar
Florent Chehab committed
16 17
    class Meta:
        model = UniversityDri
18
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
19 20


21
class UniversityDriViewSet(ModuleViewSet):
Florent Chehab's avatar
Florent Chehab committed
22 23
    queryset = UniversityDri.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityDriSerializer
24

25
    def get_queryset(self):
26
        univ_id = self.kwargs["univ_id"]
27
        return super().get_queryset().filter(universities__pk=univ_id).distinct()