Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 在postgres中插入json作为芹菜任务的一部分_Django_Postgresql_Celery - Fatal编程技术网

Django 在postgres中插入json作为芹菜任务的一部分

Django 在postgres中插入json作为芹菜任务的一部分,django,postgresql,celery,Django,Postgresql,Celery,我对Django和芹菜不熟悉 高级别: 我正在开发Django应用程序。从管理员页面使用将提交请求(作业)。这些请求将被发送到Redis。芹菜将轮询Redis并从队列中提取作业。任务完成后,结果将存储在postgres中 下面是一个示例任务,用于通过pytest.main()启动一些测试 代码将运行测试,但正如您在最后一条注释中看到的,我希望获取结果.json.report并将其存储在postgres db中[请注意,我使用助手获取由结果生成的实际报告] 这就是我感到困惑的地方 我是否需要首先基

我对Django和芹菜不熟悉

高级别:

我正在开发Django应用程序。从管理员页面使用将提交请求(作业)。这些请求将被发送到Redis。芹菜将轮询Redis并从队列中提取作业。任务完成后,结果将存储在postgres中

下面是一个示例任务,用于通过pytest.main()启动一些测试

代码将运行测试,但正如您在最后一条注释中看到的,我希望获取结果.json.report并将其存储在postgres db中[请注意,我使用助手获取由
结果生成的实际报告
]

这就是我感到困惑的地方

我是否需要首先基于将由pytest生成的json报告中的所有键创建一个模型

如果是这样,我会使用类似于
TestResultModel.objects.create(…)
的方法将报告插入postgres吗

下面是pytest.main输出的json示例

{“创建”:1535570420.542123,“持续时间”:215.14111948013306, “exitcode”:1,“root”:“/test”,“environment”:{“Python”:“3.6.6”, “平台”:“Linux-4.9.93-linuxkit-aufs-x86_64-with-debian-9.5”, “包”:{“pytest”:“3.6.2”、“py”:“1.5.4”、“pluggy”:“0.6.0”}, “插件”:{“xdist”:“1.22.5”,“元数据”:“1.7.0”,“json报告”: “0.7.0”、“分叉的”:“0.2”、“django”:“3.3.3”、“cov”:“2.5.1”、“芹菜”: “4.2.1”},“摘要”:{“通过”:34,“未通过”:7,“总计”:41}

我是否需要首先基于将由pytest生成的json报告中的所有键创建一个模型

一般来说,答案是肯定的。但它看起来不像是保存在数据库中的关系数据。因此,您可以使用并一次性插入其中的所有内容。JSONField对应于postgresql中的JSONB字段,该字段用于存储json对象,并允许搜索、修改这些对象等


您可能还想看看

非常感谢您的建议。我将集中精力实施此建议。很高兴能为您提供帮助
# task for running tests by marker 
def run_tests_mark(test_marker):
    os.chdir('/service/lib/tests')
    # only allow specific strings to be passed in by the user
    if test_marker not in ['smoke', 'regression']: # update as more tages are introduced to the project
        return 'You have entered an invalid term. Please use either smoke of regression.'
    # run pytest command with self contained reporting
    results = pytest.main(['-v', '--json-report', '-m', test_marker])
    # TODO: after tests run send json report to postgres