universityDri.py 913 Bytes
Newer Older
1
from django.db import models
2

3
from backend_app.models.abstract.module import Module, ModuleSerializer, ModuleViewSet
4 5
from backend_app.models.university import University
from backend_app.permissions.app_permissions import IsStaff, IsDri, ReadOnly
6 7


8
class UniversityDri(Module):
9
    universities = models.ManyToManyField(University, related_name="university_dri")
10 11


12
class UniversityDriSerializer(ModuleSerializer):
13 14
    class Meta:
        model = UniversityDri
15
        fields = "__all__"
16 17


18
class UniversityDriViewSet(ModuleViewSet):
19 20
    queryset = UniversityDri.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityDriSerializer
21 22
    permission_classes = (IsStaff | IsDri | ReadOnly,)
    end_point_route = r"universityDri/(?P<univ_id>[0-9]+)"
23

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