diff --git a/apps/mtm/filters.py b/apps/mtm/filters.py new file mode 100644 index 00000000..eadc80c5 --- /dev/null +++ b/apps/mtm/filters.py @@ -0,0 +1,13 @@ +from django_filters import rest_framework as filters +from apps.mtm.models import Goal + +class GoalFilter(filters.FilterSet): + class Meta: + model = Goal + fields = { + "mgroup": ["exact", "in"], + "mgroup__name": ["exact", "in"], + "goal_cate": ["exact", "in"], + "goal_cate__code": ["exact", "in"], + "year": ["exact"] + } \ No newline at end of file diff --git a/apps/mtm/views.py b/apps/mtm/views.py index c8e3f5f7..be7c7a0a 100644 --- a/apps/mtm/views.py +++ b/apps/mtm/views.py @@ -4,6 +4,7 @@ from rest_framework.mixins import ListModelMixin from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet from apps.mtm.models import Material, Mgroup, Shift, Team, Goal from apps.mtm.serializers import MaterialSerializer, MgroupSerializer, ShiftSerializer, TeamSerializer, GoalSerializer +from apps.mtm.filters import GoalFilter # Create your views here. class MaterialViewSet(CustomModelViewSet): @@ -67,5 +68,5 @@ class GoalViewSet(CustomModelViewSet): queryset = Goal.objects.all() serializer_class = GoalSerializer select_related_fields = ['mgroup', 'goal_cate'] - filterset_fields = ['mgroup', 'goal_cate', 'year', 'goal_cate__code'] + filterset_class = GoalFilter search_fields = ['name'] \ No newline at end of file