set search & filter on organization - change on herd in cooperative
This commit is contained in:
@@ -10,6 +10,7 @@ from apps.authentication.api.v1.serializers.serializer import (
|
||||
BankAccountSerializer,
|
||||
)
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.core.pagination import CustomPageNumberPagination
|
||||
from apps.authorization.api.v1 import api as authorize_view
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
@@ -193,10 +194,20 @@ class OrganizationTypeViewSet(ModelViewSet):
|
||||
serializer_class = OrganizationTypeSerializer
|
||||
|
||||
|
||||
class OrganizationViewSet(ModelViewSet):
|
||||
class OrganizationViewSet(ModelViewSet, DynamicSearchMixin):
|
||||
""" Crud operations for organization model """ #
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrganizationSerializer
|
||||
search_fields = [
|
||||
"name",
|
||||
"type__name",
|
||||
"type__key",
|
||||
"national_unique_id",
|
||||
"field_of_activity",
|
||||
"company_code",
|
||||
"province__name",
|
||||
"city__name",
|
||||
]
|
||||
|
||||
def get_all_org_child(self, org):
|
||||
descendants = []
|
||||
@@ -295,7 +306,10 @@ class OrganizationViewSet(ModelViewSet):
|
||||
organization = get_organization_by_user(request.user)
|
||||
child_organizations = self.get_all_org_child(organization)
|
||||
|
||||
page = self.paginate_queryset(child_organizations) # paginate queryset
|
||||
# search & filter
|
||||
queryset = self.filter_query(self.queryset.filter(id__in={instance.id for instance in child_organizations}))
|
||||
|
||||
page = self.paginate_queryset(queryset) # paginate queryset
|
||||
|
||||
if page is not None:
|
||||
serializer = self.serializer_class(page, many=True)
|
||||
|
||||
Reference in New Issue
Block a user