Skip to content

Commit

Permalink
refactor: studygroup/filters 에 타입 힌트 추가 #92
Browse files Browse the repository at this point in the history
  • Loading branch information
TGoddessana committed Oct 3, 2023
1 parent e5601ee commit 3812d47
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions apps/studygroup/filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.db.models import Count, F, Q
from typing import Any

from django.db.models import Count, F, Q, QuerySet
from django.utils.datetime_safe import date
from django_filters import rest_framework as filters

from apps.studygroup.models import Category, StudyGroup, StudyGroupMember, Tag


class MyStudyGroupFilter(filters.FilterSet):
class MyStudyGroupFilter(filters.FilterSet): # type: ignore
filter = filters.TypedChoiceFilter(
label="filter",
choices=(
Expand All @@ -23,7 +25,9 @@ class MyStudyGroupFilter(filters.FilterSet):
help_text="검색 조건에 따라 나와 관련된 스터디그룹을 필터링합니다.",
)

def filter_as_leader(self, queryset, name, value: str):
def filter_as_leader(
self, queryset: QuerySet[StudyGroup], name: str, value: str
) -> QuerySet[StudyGroup]:
"""
내가 리더인 스터디그룹을 필터링합니다.
"""
Expand All @@ -35,10 +39,10 @@ def filter_as_leader(self, queryset, name, value: str):

class Meta:
model = StudyGroup
fields = []
fields: list[Any] = []


class StudyGroupListFilter(filters.FilterSet):
class StudyGroupListFilter(filters.FilterSet): # type: ignore
ordering = filters.OrderingFilter(
fields=(
("created_at", "created_at"),
Expand Down Expand Up @@ -92,7 +96,9 @@ class StudyGroupListFilter(filters.FilterSet):
)

@staticmethod
def filter_is_closed(queryset, name, value):
def filter_is_closed(
queryset: QuerySet[StudyGroup], name: str, value: bool
) -> QuerySet[StudyGroup]:
"""
모집 마감에 따라 스터디그룹을 필터링합니다.
"""
Expand All @@ -105,7 +111,9 @@ def filter_is_closed(queryset, name, value):
return queryset.exclude(id__in=filtered_queryset)

@staticmethod
def filter_random(queryset, name, value):
def filter_random(
queryset: QuerySet[StudyGroup], name: str, value: bool
) -> QuerySet[StudyGroup]:
"""
True일 경우 랜덤으로 스터디그룹을 필터링합니다.
"""
Expand Down

0 comments on commit 3812d47

Please sign in to comment.