universityDri.py 808 Bytes
Newer Older
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
4 5


6
class UniversityDri(Module):
7

8
    universities = models.ManyToManyField(University, related_name="university_dri")
9

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

14

15
class UniversityDriSerializer(ModuleSerializer):
16 17
    class Meta:
        model = UniversityDri
18
        fields = "__all__"
19 20


21
class UniversityDriViewSet(ModuleViewSet):
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()