add all type to my distributions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.db.models import Q
|
||||
|
||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
||||
from apps.product.services.search.distribution_search import QuotaDistributionSearch
|
||||
from apps.core.pagination import CustomPageNumberPagination
|
||||
from rest_framework.exceptions import APIException
|
||||
from apps.product import models as product_models
|
||||
@@ -35,6 +36,14 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
||||
search_fields = ['']
|
||||
CustomPageNumberPagination.page_size = 5
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
""" search & filter in distributions or return all objects """
|
||||
|
||||
params = self.request.query_params
|
||||
query = params.get('search')
|
||||
start_date = params.get('start')
|
||||
end_date = params.get('end')
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" create distribution for organizations users """
|
||||
@@ -100,6 +109,15 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
||||
).order_by('-modify_date')
|
||||
)
|
||||
|
||||
elif query.get('param') == 'all':
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
self.queryset.filter(
|
||||
Q(assigner_organization=organization) |
|
||||
Q(assigned_organization=organization)
|
||||
).order_by('-modify_date')
|
||||
)
|
||||
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True) # noqa
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
Reference in New Issue
Block a user