countryModulesAPI.py 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from backend.models.country import Country

from backend.models.country import CountryDriSerializer
from backend.models.country import CountryScholarshipSerializer
from backend.models.country import CountryTaggedItemSerializer

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


class CountryModulesSerializer(MyModelSerializer):
    country_scholarships = CountryScholarshipSerializer(
        many=True, read_only=True)
    country_tagged_items = CountryTaggedItemSerializer(
        many=True, read_only=True)
    country_dri = CountryDriSerializer(many=True, read_only=True)

    class Meta:
        model = Country
        fields = '__all__'


class CountryModulesViewSet(MyModelViewSet):
    permission_classes = get_viewset_permissions("CountryModulesViewSet")
    serializer_class = CountryModulesSerializer
    queryset = Country.objects.all()
27
    LIST_SHOULD_BE_DETAIL = True
28
29
30
31
32
33
34
35

    def extend_queryset(self):
        country_id = self.kwargs['country_id']
        return self.my_model_queryset.filter(pk=country_id).prefetch_related(
            'country_dri',
            'country_scholarships',
            'country_tagged_items'
        )  # pylint: disable=E1101