campusModulesAPI.py 899 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
from backend.models.campus import Campus

from backend.models.campus import CampusTaggedItemSerializer

from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions


class CampusModulesSerializer(MyModelSerializer):
    campus_tagged_items = CampusTaggedItemSerializer(
        many=True, read_only=True)

    class Meta:
        model = Campus
        fields = '__all__'


class CampusModulesViewSet(MyModelViewSet):
    permission_classes = get_viewset_permissions("CampusModulesViewSet")
    serializer_class = CampusModulesSerializer
    queryset = Campus.objects.all()
22
    LIST_SHOULD_BE_DETAIL = True
23 24 25 26 27 28

    def extend_queryset(self):
        campus_id = self.kwargs['campus_id']
        return self.my_model_queryset.filter(pk=campus_id).prefetch_related(
            'campus_tagged_items'
        )  # pylint: disable=E1101