Commit f57e7b8f authored by zhengjinlei's avatar zhengjinlei

查询数据

parent d646a98d
...@@ -27,7 +27,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -27,7 +27,7 @@ class TasksApi(viewsets.ViewSet):
:param req: :param req:
:return: :return:
""" """
tasks = Tasks.objects.all().values('id', 'name') tasks = Tasks.objects.all().order_by('-createdAt').values('id', 'name')
# return render(req, 'inspect/index.html', {'tasks': tasks}) # return render(req, 'inspect/index.html', {'tasks': tasks})
return Response({'code': 0, 'msg': 'success', 'data': tasks}) return Response({'code': 0, 'msg': 'success', 'data': tasks})
...@@ -64,10 +64,13 @@ class TasksApi(viewsets.ViewSet): ...@@ -64,10 +64,13 @@ class TasksApi(viewsets.ViewSet):
task_id = req.data.get('task', '') task_id = req.data.get('task', '')
agent_name = req.data.get('agentName', '') agent_name = req.data.get('agentName', '')
start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d')) start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d'))
end_date = req.data.get('end_date', (datetime.now()+timedelta(days=1)).strftime('%Y-%m-%d')) end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
tasks = []
if task_id: if task_id:
task_condition['pk'] = task_id tk = Tasks.objects.get(pk=task_id)
tasks.append(tk)
else:
tasks = Tasks.objects.filter(**task_condition) tasks = Tasks.objects.filter(**task_condition)
return_data = {} return_data = {}
for t in tasks: for t in tasks:
...@@ -102,10 +105,13 @@ class TasksApi(viewsets.ViewSet): ...@@ -102,10 +105,13 @@ class TasksApi(viewsets.ViewSet):
task_id = req.data.get('task', '') task_id = req.data.get('task', '')
num = req.data.get('num', '10') num = req.data.get('num', '10')
start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d')) start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d'))
end_date = req.data.get('end_date', (datetime.now()+timedelta(days=1)).strftime('%Y-%m-%d')) end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
tasks = []
if task_id: if task_id:
task_condition['pk'] = task_id tk = Tasks.objects.get(pk=task_id)
tasks.append(tk)
else:
tasks = Tasks.objects.filter(**task_condition) tasks = Tasks.objects.filter(**task_condition)
return_data = {} return_data = {}
for t in tasks: for t in tasks:
...@@ -138,10 +144,13 @@ class TasksApi(viewsets.ViewSet): ...@@ -138,10 +144,13 @@ class TasksApi(viewsets.ViewSet):
task_id = req.data.get('task', '') task_id = req.data.get('task', '')
num = req.data.get('num', '10') num = req.data.get('num', '10')
start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d')) start_date = req.data.get('start_date', (datetime.now()+timedelta(days=-30)).strftime('%Y-%m-%d'))
end_date = req.data.get('end_date', (datetime.now()+timedelta(days=1)).strftime('%Y-%m-%d')) end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date} task_condition = {'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
tasks = []
if task_id: if task_id:
task_condition['pk'] = task_id tk = Tasks.objects.get(pk=task_id)
tasks.append(tk)
else:
tasks = Tasks.objects.filter(**task_condition) tasks = Tasks.objects.filter(**task_condition)
return_data = {} return_data = {}
for t in tasks: for t in tasks:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment