我定义了下面的类来为投票系统做统计。
class FormPage(AbstractForm):
submission_stats = models.JSONField(null=True, editable=False)
现在,我有submission_stats
以下格式:
[
{
"id":4,
"label":"checkboxes",
"choices":[
{
"content":"option-A",
"num_vote":0,
"user_list":[
]
},
{
"content":"option-B",
"num_vote":0,
"user_list":[
]
},
{
"content":"option-C",
"num_vote":0,
"user_list":[
]
}
]
},
{
"id":7,
"label":"Radio Button",
"choices":[
{
"content":"option-1",
"num_vote":0,
"user_list":[
]
},
{
"content":"option-2",
"num_vote":0,
"user_list":[
]
},
{
"content":"option-3",
"num_vote":0,
"user_list":[
]
}
]
}
]
例如,当我收到 2 票提交时,我想相应地更新此 JSONField 中的num_vote
(从 0 到 2)和user_list
(从[]
到[user_a, user_b]
)字段。
请问如何查询和更新嵌套 JSONField 数据中的元素?