Skip to content

Commit

Permalink
Merge pull request #251 from volunteers-for-city-projects/fix-incomes
Browse files Browse the repository at this point in the history
change serializer in incomes get, add multichoice in projects filters…
  • Loading branch information
Olga-koml authored Nov 29, 2023
2 parents 1254ba1 + c26a2a8 commit f1f6759
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
37 changes: 32 additions & 5 deletions backend/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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']
6 changes: 6 additions & 0 deletions backend/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
2 changes: 1 addition & 1 deletion backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CityFilter,
ProjectCategoryFilter,
ProjectFilter,
ProjectIncomesFilter,
SkillsFilter,
StatusProjectFilter,
TagFilter,
Expand Down Expand Up @@ -469,6 +470,7 @@ class ProjectIncomesViewSet(

queryset = ProjectIncomes.objects.all()
permission_classes = [IsVolunteer]
filterset_class = ProjectIncomesFilter

def get_queryset(self):
user = self.request.user
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit f1f6759

Please sign in to comment.