39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
| from django.shortcuts import render
 | |
| from rest_framework.mixins import ListModelMixin, CreateModelMixin
 | |
| from rest_framework.decorators import action
 | |
| from apps.qm.models import QuaStat, TestItem
 | |
| from apps.qm.serializers import QuaStatSerializer, TestItemSerializer
 | |
| from apps.qm.tasks import cal_quastat
 | |
| from rest_framework.response import Response
 | |
| 
 | |
| from apps.utils.viewsets import CustomGenericViewSet
 | |
| 
 | |
| # Create your views here.
 | |
| class TestItemViewSet(ListModelMixin, CustomGenericViewSet):
 | |
|     """
 | |
|     list:质检项目
 | |
| 
 | |
|     质检项目
 | |
|     """
 | |
|     perms_map = {'get': '*'}
 | |
|     queryset = TestItem.objects.all()
 | |
|     serializer_class = TestItemSerializer
 | |
|     filterset_fields = []
 | |
|     ordering = ['id']
 | |
| 
 | |
| class QuaStatViewSet(ListModelMixin, CreateModelMixin, CustomGenericViewSet):
 | |
|     """
 | |
|     list:质量分析报告
 | |
| 
 | |
|     质量分析报告
 | |
|     """
 | |
|     perms_map = {'get': '*', 'post': 'quastat.create'}
 | |
|     queryset = QuaStat.objects.all()
 | |
|     serializer_class = QuaStatSerializer
 | |
|     filterset_fields = ['type', 'year_s', 'month_s', 'day_s', 'material', 'testitem', 'belong_dept', 'sflog', 'sflog__mgroup']
 | |
|     select_related_fields = ['belong_dept', 'material', 'testitem']
 | |
|     
 | |
|     def perform_create(self, serializer):
 | |
|         ins = serializer.save()
 | |
|         # 计算其他方面的统计
 | |
|         cal_quastat.delay(ins.id) |