rancher setub

This commit is contained in:
2025-08-03 16:03:01 +03:30
parent 6ccbadbbdc
commit 57d1034024
13 changed files with 210 additions and 9 deletions

View File

@@ -1,11 +1,12 @@
from apps.herd.web.api.v1.serializers import HerdSerializer
from apps.herd.web.api.v1.serializers import HerdSerializer, RancherSerializer
from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.authentication.api.v1.api import UserViewSet
from rest_framework.exceptions import APIException
from rest_framework.response import Response
from rest_framework.decorators import action
from common.tools import CustomOperations
from rest_framework import viewsets
from apps.herd.models import Herd
from apps.herd.models import Herd, Rancher
from django.db import transaction
from rest_framework import status
@@ -85,3 +86,36 @@ class HerdViewSet(viewsets.ModelViewSet):
return Response(status=status.HTTP_200_OK)
except APIException as e:
return Response(e, status=status.HTTP_204_NO_CONTENT)
class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
queryset = Rancher.objects.all()
serializer_class = RancherSerializer
search_fields = [
"ranching_farm",
"first_name",
"last_name",
"mobile",
"national_code",
"birthdate",
"nationality",
"address",
"province__name",
"city__name",
]
def list(self, request, *args, **kwargs):
""" list of ranchers """
search = self.filter_query(self.queryset) # search & filter
page = self.paginate_queryset(search)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
@action(
methods=['get'],
detail=True,
)
def herds_by_rancher(self, request):
pass