尝试使用总和值 django

Trying to use sum value django

如何在查询集中使用此总和的结果?

query = some_model.objects.aggregate(Sum('some_field'))

我已经试过了

regPeso = test_model.objects.create(test_field_id =1,total_field = query)

我遇到了这个错误

Field 'total_field' expected a number but got "{'some_field__sum': x}"

我该怎么做才能解决这个错误?谢谢!

您通过下标从字典中获取给定键的值,因此:

regPeso = test_model.objects.create(
    test_field_id=1,
    total_field=<strong>query['some_field__sum']</strong>
)