Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change serializer in incomes get, add multichoice in projects filters… #251

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -605,7 +605,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 @@ -489,6 +490,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 @@ -595,6 +597,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