cityModulesAPI.py 867 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.city import City

from backend.models.city import CityTaggedItemSerializer

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


class CityModulesSerializer(MyModelSerializer):
    city_tagged_items = CityTaggedItemSerializer(
        many=True, read_only=True)

    class Meta:
        model = City
        fields = '__all__'


class CityModulesViewSet(MyModelViewSet):
    permission_classes = get_viewset_permissions("CityModulesViewSet")
    serializer_class = CityModulesSerializer
    queryset = City.objects.all()
22
    LIST_SHOULD_BE_DETAIL = True
23 24 25 26 27 28

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