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

Feauture/add project filters #97

Closed
wants to merge 2 commits into from
Closed
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
42 changes: 42 additions & 0 deletions src/backend/api/v1/projects/filters.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skill = filters.ModelMultipleChoiceFilter(queryset=Skill.objects.all())
level = filters.MultipleChoiceFilter(choices=LEVEL_CHOICES)

У проектов не должно быть непосредственной связи со скилами и уровнями. Соответственно и фильтрация так работать не должна.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django_filters.rest_framework import FilterSet
from django_filters import filters

from apps.general.constants import LEVEL_CHOICES
from apps.general.models import Skill
from apps.project.constants import (
BUSYNESS_CHOICES,
STATUS_CHOICES,
DIRECTION_CHOICES,
)
from apps.project.models import Project


class ProjectFilter(FilterSet):
"""
Класс для фильтрации проектов по имени, дате начала, дате конца, занятости в часах в неделю, статусу набора
участников, статусу проекта, направлению разработки, навыкам и уровню
"""

name = filters.CharFilter(lookup_expr="icontains")
started = filters.DateFromToRangeFilter()
ended = filters.DateFromToRangeFilter()
busyness = filters.MultipleChoiceFilter(choices=BUSYNESS_CHOICES)
recruitment_status = filters.BooleanFilter()
status = filters.MultipleChoiceFilter(choices=STATUS_CHOICES)
direction = filters.MultipleChoiceFilter(choices=DIRECTION_CHOICES)
skill = filters.ModelMultipleChoiceFilter(queryset=Skill.objects.all())
level = filters.MultipleChoiceFilter(choices=LEVEL_CHOICES)

class Meta:
model = Project
fields = (
"name",
"started",
"ended",
"busyness",
"recruitment_status",
"status",
"direction",
"skill",
"level",
)
5 changes: 4 additions & 1 deletion src/backend/api/v1/projects/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.db.models import Prefetch
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import mixins
from rest_framework.permissions import AllowAny, IsAuthenticatedOrReadOnly
from rest_framework.viewsets import GenericViewSet, ModelViewSet

from apps.general.models import Skill
from apps.project.models import Project, ProjectSpecialist

from .filters import ProjectFilter
from .constants import PROJECT_PREVIEW_MAIN_FIELDS
from .paginations import ProjectPagination, ProjectPreviewMainPagination
from .serializers import ProjectPreviewMainSerializer, ProjectSerializer
Expand All @@ -29,6 +30,8 @@ class ProjectViewSet(ModelViewSet):
permission_classes = (IsAuthenticatedOrReadOnly,)
serializer_class = ProjectSerializer
pagination_class = ProjectPagination
filter_backends = (DjangoFilterBackend,)
filterset_class = ProjectFilter


class ProjectPreviewMainViewSet(mixins.ListModelMixin, GenericViewSet):
Expand Down
6 changes: 6 additions & 0 deletions src/backend/apps/project/models.py
Copy link
Contributor

@ArtemKAF ArtemKAF Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skills = models.ManyToManyField(
Skill, related_name="projects", verbose_name="Проекты"
)
level = models.PositiveSmallIntegerField(
verbose_name="Уровень", choices=LEVEL_CHOICES, null=True, blank=True
)

Связь со скилами и уровнями проектов реализована через тех специалистов, кторые необходимы проекту.

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class Project(CreatedModifiedFields):
related_name="projects_participated",
blank=True,
)
skills = models.ManyToManyField(
Skill, related_name="projects", verbose_name="Проекты"
)
level = models.PositiveSmallIntegerField(
verbose_name="Уровень", choices=LEVEL_CHOICES, null=True, blank=True
)

class Meta:
verbose_name = "Проект"
Expand Down