我可以看到很多不同的选择,并且希望获得有关最有效或最佳实践方法的反馈。
我得到一个带filter()的Django Queryset
c_layer_points = models.layer_points.objects.filter(location_id=c_location.pk,season_id=c_season.pk,line_path_id=c_line_path.pk,radar_id=c_radar.pk,layer_id__in=c_layer_pks,gps_time__gte=start_gps,gps_time__lte=stop_gps)
此查询集可能非常大(数十万行)。
现在需要发生的是对列表的转换和对JSON的编码。
选项(我在搜索中看到的选项:]:>
示例:
gps_time = [lp.gps_time for lp in c_layer_points]; twtt = [lp.twtt for lp in c_layer_points];
- 使用values()或values_list()
最后,我想将这种格式编码为json:
{'gps_time':[list of all gps times],'twtt',[list of all twtt]}
关于实现此目标的最佳方法的任何提示,太棒了,谢谢!
我可以看到很多不同的选择,并且希望获得有关最有效或最佳实践方法的反馈。我得到了一个带filter()的Django Queryset c_layer_points = models ....
您可能无法从ORM获取所需的格式。但是,您可以有效地执行以下操作:
我建议您使用遍历查询集的方式,并使json字典元素与查询集中的元素保持一致。