37,719
社区成员
发帖
与我相关
我的任务
分享
@require_http_methods(["GET"])
def get_pe_ttm(requst):
response = {}
pettm_list = []
pe = []
pe_num = []
try:
pettm = daily_stock_market.objects.filter(stock_code='000001.SZ',market_date__gte=datetime(2016,12,12)).exclude(market_date__gte=datetime(2017,12,12))
middlterm = serializers.serialize("json",pettm,fields=('day_pe_ttm','market_date'))
pettm_list=json.loads(middlterm)
pettm_length=len(pettm_list)
for i in range(0,pettm_length):
if pettm_list[i]['fields']['market_date'] not in pe_num:
pe.append(pettm_list[i]['fields'])
pe_num.append(pettm_list[i]['fields']['market_date'])
response['list'] = pe
response['msg'] = 'success'
response['error_num'] = 0
except Exception as e:
response['msg'] = str(e)
response['error_num'] = 1
# return HttpResponse(JsonResponse(response),content_type='application/json')
return JsonResponse(response)