diff --git a/backend/api/filters.py b/backend/api/filters.py index 77a009f..08b196e 100644 --- a/backend/api/filters.py +++ b/backend/api/filters.py @@ -6,7 +6,7 @@ from taggit.models import Tag from content.models import City, Skills -from projects.models import Category, Project +from projects.models import Category, Project, ProjectIncomes class ProjectCategoryFilter(FilterSet): @@ -69,12 +69,25 @@ class ProjectFilter(FilterSet): - /projects/?end_datetime=31.12.2023 """ - categories = django_filters.CharFilter( - field_name='categories', lookup_expr='exact' + categories = filters.ModelMultipleChoiceFilter( + queryset=Category.objects.all(), + field_name='categories', + to_field_name='id', + # conjoined=True ) - skills = django_filters.CharFilter( - field_name='skills', lookup_expr='exact' + + skills = filters.ModelMultipleChoiceFilter( + queryset=Skills.objects.all(), + field_name='skills', + to_field_name='id', + # conjoined=True, # все указанные навыки должны быть одновременно в проекте ) + + # city = filters.ModelMultipleChoiceFilter( + # queryset=City.objects.all(), + # field_name='city__name', !!!!!!!! поиск указан по имени, исправить на id если надо. + # to_field_name='name' + # ) city = django_filters.CharFilter(field_name='city', lookup_expr='exact') start_datetime = django_filters.DateTimeFilter( field_name='start_datetime', lookup_expr='gte' @@ -294,3 +307,17 @@ def filter_queryset(self, queryset): class Meta: model = Project fields = [] + + +class ProjectIncomesFilter(django_filters.FilterSet): + """ + Фильтр заявок по id Проекта. + + Пример фильтра /api/incomes/?project_id=1 + """ + + project_id = django_filters.NumberFilter(field_name='project__id') + + class Meta: + model = ProjectIncomes + fields = ['project_id'] diff --git a/backend/api/schemas.py b/backend/api/schemas.py index 5cdabc3..7de62e6 100644 --- a/backend/api/schemas.py +++ b/backend/api/schemas.py @@ -34,3 +34,9 @@ 'Пример запроса /projects/me/?is_favorited=true') ), ] + +project_incomes_filter_params = openapi.Parameter( + 'project_id', openapi.IN_QUERY, type=openapi.TYPE_STRING, + description=('Фильтрует заявки по id проекта. ' + 'Пример запроса /api/incomes/?project_id=1') + ) diff --git a/backend/api/serializers.py b/backend/api/serializers.py index 01a14f5..d3038a6 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -612,7 +612,7 @@ class ProjectIncomesGetSerializer(serializers.ModelSerializer): """ volunteer = VolunteerGetSerializer(read_only=True) - project = ProjectSerializer(read_only=True) + project = ProjectGetSerializer(read_only=True) class Meta: model = ProjectIncomes diff --git a/backend/api/views.py b/backend/api/views.py index ded409d..342718b 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -33,6 +33,7 @@ CityFilter, ProjectCategoryFilter, ProjectFilter, + ProjectIncomesFilter, SkillsFilter, StatusProjectFilter, TagFilter, @@ -469,6 +470,7 @@ class ProjectIncomesViewSet( queryset = ProjectIncomes.objects.all() permission_classes = [IsVolunteer] + filterset_class = ProjectIncomesFilter def get_queryset(self): user = self.request.user @@ -575,6 +577,12 @@ def reject_incomes(self, request, pk): response_data = serializer.reject_incomes(instance) return Response(response_data, status=status.HTTP_200_OK) + @swagger_auto_schema( + manual_parameters=[schemas.project_incomes_filter_params] + ) + def list(self, request, *args, **kwargs): + return super().list(request, *args, **kwargs) + class ProjectMeViewSet(viewsets.GenericViewSet, mixins.ListModelMixin): """