分析这两个接口
def get_topology_by_project(request):
if request.method == "POST":
project_id = request.POST.get('project_id')
print(project_id)
topologies = Topology.objects.filter(project_id_id=project_id)
topology_list = []
for topology in topologies:
topology_dict = {
'topology_id': topology.topology_id,
'name': topology.name,
'date': topology.date,
'json': js.loads(topology.json),
'project_id': topology.project_id_id,
}
topology_list.append(topology_dict)
return JsonResponse({'data': topology_list, 'message': '获取成功'}, status=200)
return JsonResponse({'message': '无效的请求方法'}, status=405)
def get_eqtopology_by_topology(request):
if request.method == "POST":
topology_id = request.POST.get('topology_id')
eq_topologies = Eq_Topology.objects.filter(topology_id__topology_id=topology_id)
eq_topology_list = []
for eq_topology in eq_topologies:
print(topology_id)
eq_topology_dict = {
'eq_topology_id': eq_topology.eq_topology_id,
'json': js.loads(eq_topology.json),
'topology_id': topology_id,
}
eq_topology_list.append(eq_topology_dict)
return JsonResponse({'data': eq_topology_list, 'message': '获取成功'}, status=200)
return JsonResponse({'message': '无效的请求方法'}, status=405)
本来是打算将内容直接照搬过来,但是发现竟然报错了
原因是因为我在model中定义的时候project主键是project_id但是topology的主键是自动生成的id,所以filter的参数写法不同,__表示关联
根本原因还是我的命名有问题,建议不要用_id去命名