from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet

from ..models import FormationEmploi
from ..serializers.formation_emploi import FormationEmploiSerializer
from .commun import (GestionnairePermission, execution_time_viewset,
                     query_count_viewset)


@execution_time_viewset
@query_count_viewset
class FormationEmploiView(ModelViewSet):
    """
    Cette classe est dédiée au vue des FormationEmplois.
    """
    permission_classes = [IsAuthenticated, GestionnairePermission]
    serializer_class = FormationEmploiSerializer

    # important : mettre à jour quand le serializer change
    def get_queryset(self):
        Cols = FormationEmploi.Cols
        return FormationEmploi.objects.select_related(Cols.REL_MERE)

