city & province list for pos device
This commit is contained in:
0
apps/authentication/pos/__init__.py
Normal file
0
apps/authentication/pos/__init__.py
Normal file
0
apps/authentication/pos/api/__init__.py
Normal file
0
apps/authentication/pos/api/__init__.py
Normal file
0
apps/authentication/pos/api/v1/__init__.py
Normal file
0
apps/authentication/pos/api/v1/__init__.py
Normal file
31
apps/authentication/pos/api/v1/api.py
Normal file
31
apps/authentication/pos/api/v1/api.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
class CityViewSet(ModelViewSet, SoftDeleteMixin): # noqa
|
||||
""" Crud operations for city model """ #
|
||||
queryset = City.objects.all()
|
||||
serializer_class = CitySerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
""" return list of cities by province """
|
||||
|
||||
serializer = self.serializer_class(
|
||||
self.queryset.filter(
|
||||
province_id=int(request.GET['province'])
|
||||
), many=True
|
||||
)
|
||||
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
|
||||
0
apps/authentication/pos/api/v1/serializer.py
Normal file
0
apps/authentication/pos/api/v1/serializer.py
Normal file
12
apps/authentication/pos/api/v1/urls.py
Normal file
12
apps/authentication/pos/api/v1/urls.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from apps.authentication.pos.api.v1.api import CityViewSet, ProvinceViewSet
|
||||
from django.urls import path, include
|
||||
from rest_framework import routers
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
|
||||
router.register(r'city', CityViewSet, basename='city')
|
||||
router.register(r'province', ProvinceViewSet, basename='province')
|
||||
|
||||
urlpatterns = [
|
||||
path('api/v1/', include(router.urls))
|
||||
]
|
||||
@@ -7,4 +7,5 @@ router.register('', '', basename='')
|
||||
app_name = "authentication"
|
||||
urlpatterns = [
|
||||
path('api/v1/', include('apps.authentication.api.v1.urls')),
|
||||
path('pos/', include('apps.authentication.pos.api.v1.urls')),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user