feat: 增加mio返回is_tested
This commit is contained in:
parent
b8c0a9b420
commit
f8416d91b6
|
@ -1,7 +1,6 @@
|
||||||
from django_filters import rest_framework as filters
|
from django_filters import rest_framework as filters
|
||||||
from apps.inm.models import MaterialBatch, MIO
|
from apps.inm.models import MaterialBatch, MIO
|
||||||
from django.db.models import Q
|
from django.db.models import Q, Subquery, OuterRef
|
||||||
|
|
||||||
|
|
||||||
class MaterialBatchFilter(filters.FilterSet):
|
class MaterialBatchFilter(filters.FilterSet):
|
||||||
|
|
||||||
|
@ -20,7 +19,8 @@ class MioFilter(filters.FilterSet):
|
||||||
materials__type = filters.CharFilter(
|
materials__type = filters.CharFilter(
|
||||||
method='filter_materials__type', label='物料类型')
|
method='filter_materials__type', label='物料类型')
|
||||||
materials__type__in = filters.CharFilter(
|
materials__type__in = filters.CharFilter(
|
||||||
method='filter_materials__type__in', label="物料类型多选,")
|
method='filter_materials__type__in', label="物料类型多选")
|
||||||
|
# is_testd = filters.CharFilter(label="是否已检验yes/no", method="filter_is_testd")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MIO
|
model = MIO
|
||||||
|
@ -44,3 +44,11 @@ class MioFilter(filters.FilterSet):
|
||||||
if value:
|
if value:
|
||||||
return queryset.filter(Q(materials__type__in=value.split(',')) | Q(materials__isnull=True)).distinct()
|
return queryset.filter(Q(materials__type__in=value.split(',')) | Q(materials__isnull=True)).distinct()
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
# def filter_is_testd(self, queryset, name, value):
|
||||||
|
# if value == "yes":
|
||||||
|
# return queryset.filter(item_mio__test_date__isnull=False).distinct() # 这里有问题,需要用到子查询影响性能
|
||||||
|
# elif value == "no":
|
||||||
|
# return queryset.filter(item_mio__test_date__isnull=True).distinct()
|
||||||
|
# else:
|
||||||
|
# return queryset
|
||||||
|
|
|
@ -147,6 +147,22 @@ class MIOViewSet(CustomModelViewSet):
|
||||||
search_fields = ['id', 'number', 'item_mio__batch', 'item_mio__material__name', 'item_mio__material__specification', 'item_mio__material__model']
|
search_fields = ['id', 'number', 'item_mio__batch', 'item_mio__material__name', 'item_mio__material__specification', 'item_mio__material__model']
|
||||||
data_filter = True
|
data_filter = True
|
||||||
|
|
||||||
|
def add_info_for_list(self, data):
|
||||||
|
# 获取检验状态
|
||||||
|
mio_dict = {}
|
||||||
|
for item in data:
|
||||||
|
item['is_tested'] = None
|
||||||
|
mio_dict[item['id']] = item
|
||||||
|
mioitems = list(MIOItem.objects.filter(mio__id__in=mio_dict.keys()).values_list("mio__id", "test_date"))
|
||||||
|
for item in mioitems:
|
||||||
|
mioId, test_date = item
|
||||||
|
is_tested = False
|
||||||
|
if test_date:
|
||||||
|
is_tested = True
|
||||||
|
mio_dict[mioId]['is_tested'] = is_tested
|
||||||
|
datax = [mio_dict[key] for key in mio_dict.keys()]
|
||||||
|
return datax
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
if self.action in ['create', 'update', 'partial_update']:
|
if self.action in ['create', 'update', 'partial_update']:
|
||||||
type = self.request.data.get('type')
|
type = self.request.data.get('type')
|
||||||
|
|
Loading…
Reference in New Issue