feat: sflog filter

This commit is contained in:
caoqianming 2023-06-30 10:22:46 +08:00
parent d285e09c5c
commit a6167294f7
2 changed files with 16 additions and 1 deletions

14
apps/wpm/filters.py Normal file
View File

@ -0,0 +1,14 @@
from django_filters import rest_framework as filters
from apps.wpm.models import SfLog
['mgroup', 'shift', 'team', 'leader', 'team__belong_dept']
class SfLogFilter(filters.FilterSet):
class Meta:
model = SfLog
fields = {
"mgroup": ["exact"],
"shift": ["exact"],
"team": ["exact"],
"leader": ["exact"],
"team__belong_dept": ["exact"],
"end_time": ["day", "month", "year"]
}

View File

@ -9,6 +9,7 @@ from rest_framework.mixins import DestroyModelMixin, UpdateModelMixin, ListModel
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
from apps.wpm.models import SfLog, StLog, StSfLog
from apps.wpm.serializers import SfLogSerializer, StLogSerializer, StSfLogSerializer
from apps.wpm.filters import SfLogFilter
# Create your views here.
class StLogViewSet(ListModelMixin, CustomGenericViewSet):
@ -35,7 +36,7 @@ class SfLogViewSet(UpdateModelMixin, ListModelMixin, DestroyModelMixin, CustomGe
queryset = SfLog.objects.all()
serializer_class = SfLogSerializer
select_related_fields = ['mgroup', 'shift', 'team', 'leader']
filterset_fields = ['mgroup', 'shift', 'team', 'leader', 'team__belong_dept']
filterset_class = SfLogFilter
search_fields = ['note']
ordering = ['-start_time']