|
|
|
@ -27,17 +27,32 @@ class XZNSHModelViewSet(viewsets.ModelViewSet):
|
|
|
|
|
filterset_class = SerialFilter
|
|
|
|
|
|
|
|
|
|
def get_events(self, request, *args, **kwargs):
|
|
|
|
|
res = self.queryset.values('event_type').annotate(count=Count('event_type')).order_by('-count')
|
|
|
|
|
result = list(res)
|
|
|
|
|
res = self.queryset.values("event_type").filter(event_type__isnull=False).annotate(count=Count("event_type")).order_by('-count')
|
|
|
|
|
response = self.filter_filed("event_type", res)
|
|
|
|
|
return Response(response)
|
|
|
|
|
|
|
|
|
|
def get_scenes(self, request, *args, **kwargs):
|
|
|
|
|
res = self.queryset.values("scene").filter(scene__isnull=False).annotate(count=Count("scene")).order_by('-count')
|
|
|
|
|
response = self.filter_filed("scene", res)
|
|
|
|
|
return Response(response)
|
|
|
|
|
|
|
|
|
|
def get_violation_reason(self, request, *args, **kwargs):
|
|
|
|
|
res = self.queryset.values("violation_reason").filter(violation_reason__isnull=False).annotate(count=Count("violation_reason")).order_by('-count')
|
|
|
|
|
response = self.filter_filed("violation_reason", res)
|
|
|
|
|
return Response(response)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def filter_filed(filed_name, query_set):
|
|
|
|
|
result = list(query_set)
|
|
|
|
|
data = dict()
|
|
|
|
|
for index, item in enumerate(result, 1):
|
|
|
|
|
data[index] = item.get('event_type')
|
|
|
|
|
data[index] = item.get(filed_name)
|
|
|
|
|
response = {
|
|
|
|
|
'success': True,
|
|
|
|
|
'msg': '查询成功',
|
|
|
|
|
'data': data
|
|
|
|
|
}
|
|
|
|
|
return Response(response)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RegisterLoginViewSet(viewsets.ModelViewSet):
|
|
|
|
|