2025-09-07 15:17:32 +03:30
|
|
|
from apps.authentication.api.v1.serializers.serializer import (
|
|
|
|
|
CitySerializer,
|
|
|
|
|
ProvinceSerializer
|
|
|
|
|
)
|
|
|
|
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
|
|
|
|
from apps.authentication.models import City, Province
|
|
|
|
|
from rest_framework.viewsets import ModelViewSet
|
|
|
|
|
from rest_framework.response import Response
|
2025-09-07 15:18:10 +03:30
|
|
|
from rest_framework.permissions import AllowAny
|
2025-09-07 15:17:32 +03:30
|
|
|
from rest_framework import status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CityViewSet(ModelViewSet, SoftDeleteMixin): # noqa
|
|
|
|
|
""" Crud operations for city model """ #
|
|
|
|
|
queryset = City.objects.all()
|
|
|
|
|
serializer_class = CitySerializer
|
2025-09-07 15:18:10 +03:30
|
|
|
permission_classes = [AllowAny]
|
2025-09-07 15:17:32 +03:30
|
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
|
|
""" return list of cities by province """
|
2025-09-08 16:36:42 +03:30
|
|
|
if 'province' in self.request.query_params.keys():
|
|
|
|
|
query = self.queryset.filter(province_id=int(request.GET['province']))
|
|
|
|
|
else:
|
|
|
|
|
query = self.queryset
|
2025-09-07 15:17:32 +03:30
|
|
|
|
2025-09-08 16:36:42 +03:30
|
|
|
serializer = self.serializer_class(query, many=True)
|
2025-09-07 15:17:32 +03:30
|
|
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProvinceViewSet(ModelViewSet, SoftDeleteMixin):
|
|
|
|
|
""" Crud operations for province model """ #
|
|
|
|
|
queryset = Province.objects.all()
|
|
|
|
|
serializer_class = ProvinceSerializer
|
2025-09-07 15:18:10 +03:30
|
|
|
permission_classes = [AllowAny]
|