universityDri.py 722 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
class UniversityDriSerializer(ModuleSerializer):
12 13
    class Meta:
        model = UniversityDri
14
        fields = "__all__"
15 16


17
class UniversityDriViewSet(ModuleViewSet):
18 19
    queryset = UniversityDri.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityDriSerializer
20

21
    def get_queryset(self):
22
        univ_id = self.kwargs["univ_id"]
23
        return super().get_queryset().filter(universities__pk=univ_id).distinct()