Django:迭代数据

时间:2017-09-06 10:20:48

标签: python django

我有一个变量cc,我在其中从会话中获取数据:

cc = request.session['cc_list']

,数据采用以下格式:

[
{"model": "InBound.challengecode", "pk": 1, "fields": {"challenge_code": 50, 
"sve_challenge_text": "Good"}}, 
{"model": "InBound.challengecode", "pk": 2, "fields": {"challenge_code": 48, 
"sve_challenge_text": "Voter Not Signed"}}
]

现在我想知道如何迭代它并获取challenge_codesve_challenge_text的值,因为每当我迭代它的开始时,会按'[', '{', '"'.....这样的字符进行迭代。

我将数据设置为会话:

class ViewChallengeCodes(PermissionRequiredMixin, ExportMixin, SingleTableView):
model = ChallengeCode
table_class = ChallengeCodesTable
permission_required = ('InBound.list_challenge',)
table_pagination = {'per_page': 20}

def get_queryset(self):
    challenge_code = super().get_queryset().filter(project__record_status=BaseModel.RecordActive).exclude(record_status=BaseModel.RecordDeleted)
    cc_list = serializers.serialize('json', list(challenge_code), fields=('challenge_code', 'sve_challenge_text'))

    self.request.session['cc_list'] = cc_list

    return challenge_code

提前致谢

0 个答案:

没有答案